Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using:

 

If DataRead.Read() Then
               While DataRead.Read
                   cbCompList.Items.Add(DataRead.Item("competition"))
               End While
End If

 

The problem is when it runs, the datareader populates the combo box but skips the first record in the table. Does anyone know a way I can have all records returned.

 

Thanks

Visit: VBSourceSeek - The VB.NET sourcecode library

 

 

"A mere friend will agree with you, but a real friend will argue."
Posted
That will work, and maybe I never explained fully enough - the reason I have the IF statement is to check for EOF. The While statement doesn't, as far as I can see, check for this. So if my table has no records it will return 0 records but I want a way of catching this and displaying a msgbox e.t.c.

Visit: VBSourceSeek - The VB.NET sourcecode library

 

 

"A mere friend will agree with you, but a real friend will argue."
Posted

Then possibly try:

 

If DataRead.Read() Then
               cbCompList.Items.Add(DataRead.Item("competition"))
               While DataRead.Read
                   cbCompList.Items.Add(DataRead.Item("competition"))
               End While
End If

  • *Experts*
Posted

You should use the following. You don't need the "If"

While DataRead.Read
   cbCompList.Items.Add(DataRead.Item("competition"))
End While

 

According to the Help, the DataReader begins before the first record. The first call to Read advances the pointer to the first record but only if it exists. If it doesn't the Read method returns false and you'll never get in your While loop.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...