|
-
Sep 19th, 2002, 12:23 AM
#1
Thread Starter
Junior Member
Darn DataReader!!!!
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.
-
Sep 19th, 2002, 12:27 AM
#2
Thread Starter
Junior Member
Correction to the code...
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
-
Sep 19th, 2002, 01:01 AM
#3
Thread Starter
Junior Member
Follow-up
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 ?
-
Sep 20th, 2002, 11:01 AM
#4
Thread Starter
Junior Member
I Messed up!!!!!
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..)
-
Sep 20th, 2002, 11:49 AM
#5
Lively Member
I dont use the datareader object much i usually use the dataset object thoguh I thoguht that the datareader automatically looped
"All those who wonder are not lost" -j.r.r tolkien
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|