PDA

Click to See Complete Forum and Search --> : Darn DataReader!!!!


kprashan
Sep 19th, 2002, 12:23 AM
OK, I am trying to get to an ACCESS DB with a DataReader but my code just doesnt want to work

Dim MyConnection as OLEDBConnection


MyConnection = New OleDBConnection("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & fDir.AppDomainAppPath & "CTDBv1.mdb;")

Dim DeleteBUSADD As String = "SELECT * FROM BUSADD"
Dim catCMD2 As OleDbCommand = New OleDbCommand(DeleteBUSADD, MyConnection)
Dim custReader2 As OleDbDataReader = catCMD2.ExecuteReader()


Do While custReader2.Read()
Message.InnerHtml = "WHAZZUP"
Message.Style("color") = "red"
Loop
custReader2.Close
MyConnection.Close

I have 2 records in my database, but my code just doesn't get into the Do Loop. Any pointers???

I have imported System.Data and System.Data.OLeDb too.

kprashan
Sep 19th, 2002, 12:27 AM
New Code... still doesnt work :-(

Dim MyConnection as OLEDBConnection


MyConnection = New OleDBConnection("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & fDir.AppDomainAppPath & "CTDBv1.mdb;")

MyConnection.Open()

Dim DeleteBUSADD As String = "SELECT * FROM BUSADD"
Dim catCMD2 As OleDbCommand = New OleDbCommand(DeleteBUSADD, MyConnection)
Dim custReader2 As OleDbDataReader = catCMD2.ExecuteReader()


Do While custReader2.Read()
Message.InnerHtml = "WHAZZUP"
Message.Style("color") = "red"
Loop
custReader2.Close
MyConnection.Close

kprashan
Sep 19th, 2002, 01:01 AM
I tried having more than one record in the database table.

When I have a single record, the OLEDBReader. Read returns a False value. However, when I have more than one record, it returns a true value.

Is this how it always behaves ?
Am I doing something wrong/stupid ?

kprashan
Sep 20th, 2002, 11:01 AM
Dear all,
I messed up with the data reader thing. As most of you know the Reader object points to a 'position prior to the first record in the database'. I used to open my database midway just to check whether the existing records were OK. Once I did that, the Reader pointer shifted to the first record in the table.

And after that... I used to end up with less than one record...


So...

Do not open your DB midway... (The lesson I learnt today..)

robdotnet00
Sep 20th, 2002, 11:49 AM
I dont use the datareader object much i usually use the dataset object thoguh I thoguht that the datareader automatically looped