stustarz Posted February 24, 2003 Posted February 24, 2003 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 Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
mhsueh001 Posted February 24, 2003 Posted February 24, 2003 Try Try getting rid of the line with the If statement In other words try just: While DataRead.Read cbCompList.Items.Add(DataRead.Item("competition")) End While Quote
stustarz Posted February 24, 2003 Author Posted February 24, 2003 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. Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
mhsueh001 Posted February 24, 2003 Posted February 24, 2003 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 Quote
stustarz Posted February 24, 2003 Author Posted February 24, 2003 It works - fantastic thanks! Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
a_jam_sandwich Posted February 25, 2003 Posted February 25, 2003 bear in mind every time anything uses the dataread.read the pointer for the data will move forward one record. Andy Quote Code today gone tomorrow!
*Experts* Nerseus Posted February 25, 2003 *Experts* Posted February 25, 2003 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 Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.