Thursday, March 22, 2012

trouble with read method in oledbdatareader object

Public Function GetNextCounter(ByVal QueuePath As String) As Integer
Dim ObjConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & QueuePath)
Dim intGetNextCounter as integer
Dim rdr as OleDbDataReader
Dim ObjCmd as new OleDbCommand("Select * FROM tblReportQueue_ID", ObjConn)

ObjConn.Open()
If rdr.Read then
rdr = ObjCmd.ExecuteReader()
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if
ObjConn.close()

GetNextCounter = intGetNextCounter
End Function

When I compile the page that this function is in, I get an error message saying "Object reference not set to an instance of an object." The error occurs on the line

If rdr.Read then

Can anyone give me a hand as to what went wrong? ThanksMove


rdr = ObjCmd.ExecuteReader()

Before you read rdr
i.e

rdr = ObjCmd.ExecuteReader()
If rdr.Read then
intGetNextCounter = rdr.GetInt32(0)
else
intGetNextCounter = 90
end if

0 comments:

Post a Comment