-
Re: why it always reads from second record?
> Why the following loop always reads from the
> second record?
Holly: The .Read method reads the next record; you're calling it twice:
' Reads first record
If db.dbReader.Read() = True Then
' Reads second record
Do While db.dbReader.Read
Simply eliminate the outer If...Then, and you'll see all the records.
--
Phil Weber
-
Re: why it always reads from second record?
Thanks, Phil. But i want to use 'If...then' to check whether there are any
records before i do loop.
Holly
"Phil Weber" <philweber@hotmail.com> wrote:
> > Why the following loop always reads from the
> > second record?
>
>Holly: The .Read method reads the next record; you're calling it twice:
>
> ' Reads first record
> If db.dbReader.Read() = True Then
> ' Reads second record
> Do While db.dbReader.Read
>
>Simply eliminate the outer If...Then, and you'll see all the records.
>--
>Phil Weber
>
-
Re: why it always reads from second record?
> Thanks, Phil. But I want to use 'If...Then' to check
> whether there are any records before I do loop.
Holly: Why? The loop won't do anything if there are no records.
There's no way in .NET 1.0 to check whether a DataReader contains data
(version 1.1 adds a .HasRows method), and a DataReader is forward-only, so
there's no way to reset the record pointer to the beginning of the
DataReader after you've started reading.
You could use a DataSet instead of a DataReader; that would allow you to
determine the row count before your loop. Or you could do a separate query
(SELECT COUNT(*)...) to determine the number of rows that will be returned
before you actually query for the data.
--
Phil Weber
-
Re: why it always reads from second record?
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