Click to See Complete Forum and Search --> : tryin to run a web counter in vb.net


riddim
10-16-2006, 01:42 PM
I keep getting a error

No data exists for the row/column.
..but I can see there is data in the table :confused:

i got 2 columns: id,Hit_Count

can anyone help me?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
Dim nCount As Int32
nCount = GetCounterValue()
'displays the value
lblTest.Text = nCount.ToString()
End If
End Sub

Private Function GetCounterValue() As Int32
Dim objCmd As OleDbCommand
Dim objReader As OleDbDataReader
Dim strSQL As String
Dim intNewCount As Int32
Dim MyConn As OleDbConnection = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Michael Cooper\My Documents\TempSave\Clients\PowerData\subprojects\ariel\mlkweb\db\ariel.mdb")
strSQL = "SELECT Hit_Count FROM tblHits"
'pass the string to the database
objCmd = New OleDbCommand(strSQL, MyConn)
If MyConn.State = ConnectionState.Closed Then
MyConn.Open()
End If
objReader = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
With objReader
intNewCount = CInt(.Item("Hit_Count")) + 1
End With

objReader.Close()

' ||||| Calling the Update Hit Count
Call Update_HitCount(intNewCount)
' ||||| Return the updated count
Return intNewCount

End Function

Private Sub Update_HitCount(ByVal intValue As Int32)
' ||||| Could have made this a class visible variable
Dim MyConn As OleDbConnection = New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Michael Cooper\My Documents\TempSave\Clients\PowerData\subprojects\ariel\mlkweb\db\ariel.mdb")
Dim strSQL As String
Dim objCmd As OleDbCommand
Dim intRecords As Integer
strSQL = "UPDATE tblHits "
strSQL &= "SET Hit_Count = " & CStr(intValue)
strSQL *= " WHERE ID = 1" ' ||||| The Primary Key to the Only row in table

objCmd = New OleDbCommand(strSQL, MyConn)
intRecords = objCmd.ExecuteNonQuery() ' ||||| Returns the number of rows affected
MyConn.Close()

End Sub

Cstick
10-17-2006, 10:35 PM
objReader = objCmd.ExecuteReader(CommandBehavior.CloseConnection)

'Start reading first
objReader.Read()

With objReader
intNewCount = CInt(.Item("Hit_Count")) + 1
End With

riddim
10-18-2006, 03:41 PM
hey thanks..that was the problem..i didnt notice it..before....