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
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