Problem in storing values from Executescaler() (inside a data grid

G

Guest

Problem in storing values from Executescaler() (inside a data grid.)

Situation:

I have placed a panel inside a datagrid, which populate a table from a
database. Now, I run a query to compare that the user ip address with the
database. If the query fetches a record. The panel is set to visible else
other textbox set to visible. Following are the code below.

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.ItemCommand

Select Case e.CommandName

Case "Open_panel"
' users IP address.
Dim UserIP As String
UserIP = (Request.UserHostAddress)
' Get the IP address from database
'Open the connection, and execute the query...
Dim intCount As Integer
Dim cmdvrfy As SqlCommand
cmdvrfy = New SqlCommand("Select COUNT(*) As RatingCount
FROM tbl_rating Where DocumentID =" & DocumentID & "AND ip ='" & UserIP &
"';", conPubs)
conPubs.Open()
cmdvrfy.Connection = conPubs
cmdvrfy.CommandType = CommandType.Text

intCount = cmdvrfy.ExecuteScalar()
conPubs.Close()
If intCount = 0 Then '127.0.0.1
'Opens the Panel for the user !
e.Item.FindControl("Panel1").Visible = True

Else
e.Item.FindControl("Label1").Visible = True
End If

But the value for intCount is showing me as zero even though the table
contain 4 record of that ip and DocumentID..i exactly don’t know where the
problem is..any thoughts of you will be a great help for me…


Thx
Jk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top