why it always reads from second recond?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: why it always reads from second recond?

  1. #1
    Holly Guest

    why it always reads from second recond?


    Hi, smart people,
    Why the following loop always reads from the second recond? (i have to add
    some codes to show the first record before 'Do While' every time).In VB6,
    i could use rs.movefirst to control it. Do you guy have any idea what is
    the equivalent of rs.movefirst in vb.net or any other solution?
    Thanks,
    Holly


    db.OpenDatabase()
    strSQL = "Select * from terms order by name"
    db.OpenTable(strSQL)
    db.dbReader = db.dbCmd.ExecuteReader()
    If db.dbReader.Read() = True Then

    Do While db.dbReader.Read
    msgbox (db.dbReader.GetValue(0))
    Loop

    End If

  2. #2
    Arthur Wood Guest

    Re: why it always reads from second recond?


    Holly, try it this way:

    db.OpenDatabase()
    strSQL = "Select * from terms order by name"
    db.OpenTable(strSQL)
    db.dbReader = db.dbCmd.ExecuteReader()
    If db.dbReader.Read() = True Then
    ' if you get here, there was AT LEAST ONE RECORD, so dislay the msgbox
    MessagBox.Show(db.dbReader.GetValue(0))
    'now try to read ADDITIONAL records
    Do While db.dbReader.Read
    MessagBox.Show(db.dbReader.GetValue(0))
    Loop

    End If


    If your code passes the first test, there was AT LEAST one record (read with
    the initial dbReader.Read() method call), so display it. Then proceed with
    the inner loop, to read the additional records (if there are any)

    Arthur Wood



    "Holly" <Holly248@hotmail.com> wrote:
    >
    >Hi, smart people,
    >Why the following loop always reads from the second recond? (i have to add
    >some codes to show the first record before 'Do While' every time).In VB6,
    >i could use rs.movefirst to control it. Do you guy have any idea what is
    >the equivalent of rs.movefirst in vb.net or any other solution?
    >Thanks,
    >Holly
    >
    >
    > db.OpenDatabase()
    > strSQL = "Select * from terms order by name"
    > db.OpenTable(strSQL)
    > db.dbReader = db.dbCmd.ExecuteReader()
    > If db.dbReader.Read() = True Then
    >
    > Do While db.dbReader.Read
    > msgbox (db.dbReader.GetValue(0))
    > Loop
    >
    > End If



  3. #3
    Jason Sobell iGadget Guest

    Re: why it always reads from second recond?

    Simpler still, simply remove the If statement:

    db.OpenDatabase()
    strSQL = "Select * from terms order by name"
    db.OpenTable(strSQL)
    db.dbReader = db.dbCmd.ExecuteReader()

    Do While db.dbReader.Read()
    MessagBox.Show(db.dbReader.GetValue(0))
    Loop

    Cheers,
    Jason

    On 14 Mar 2003 16:10:15 -0800, Arthur Wood wrote:
    > Holly, try it this way:
    >
    > db.OpenDatabase()
    > strSQL = "Select * from terms order by name"
    > db.OpenTable(strSQL)
    > db.dbReader = db.dbCmd.ExecuteReader()
    > If db.dbReader.Read() = True Then
    > ' if you get here, there was AT LEAST ONE RECORD, so dislay the msgbox
    > MessagBox.Show(db.dbReader.GetValue(0))
    > 'now try to read ADDITIONAL records
    > Do While db.dbReader.Read
    > MessagBox.Show(db.dbReader.GetValue(0))
    > Loop
    >
    > End If
    >
    >
    > If your code passes the first test, there was AT LEAST one record (read with
    > the initial dbReader.Read() method call), so display it. Then proceed with
    > the inner loop, to read the additional records (if there are any)
    >
    > Arthur Wood
    >
    >
    >
    > "Holly" <Holly248@hotmail.com> wrote:
    >>
    >>Hi, smart people,
    >>Why the following loop always reads from the second recond? (i have to add
    >>some codes to show the first record before 'Do While' every time).In VB6,
    >>i could use rs.movefirst to control it. Do you guy have any idea what is
    >>the equivalent of rs.movefirst in vb.net or any other solution?
    >>Thanks,
    >>Holly
    >>
    >>
    >> db.OpenDatabase()
    >> strSQL = "Select * from terms order by name"
    >> db.OpenTable(strSQL)
    >> db.dbReader = db.dbCmd.ExecuteReader()
    >> If db.dbReader.Read() = True Then
    >>
    >> Do While db.dbReader.Read
    >> msgbox (db.dbReader.GetValue(0))
    >> Loop
    >>
    >> End If


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center