-
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
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks