Results 1 to 5 of 5

Thread: Darn DataReader!!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    18

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

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    18

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    18

    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 ?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    18

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

  5. #5
    Lively Member
    Join Date
    Aug 2002
    Location
    outerspace
    Posts
    126
    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
  •  



Click Here to Expand Forum to Full Width