Vb.net Reading sql server table

Hi Experts

Using while reader.read to get the records from a sql Database table
there are 4 records but using the following I am getting only the first record

Dim sql as String = "Select Description from testfilename"
Dim Count as Integer = 0

Read test File

Do while Reader.read
      Dim FieldName as Reader.getstring(count)
     count = count + 1
     combobox.items.add(fieldname)
loop

Thanks for the help
KevinfeeningAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
then you really need to do this, to get the first column of each record:
Dim FieldName as String = Reader.getstring(0)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Dim FieldName as Reader.getstring(count)
is likely
Dim FieldName as String = Reader.getstring(0)
0
 
Akilandeshwari NCommented:
Declare the variable FieldName outside the loop
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
KevinfeeningAuthor Commented:
Sorry to Guy Hengel Dim FieldName as Reader.getstring(count) was actually
Dim FieldName as String = Reader.getstring(count)  

Declaring the variable outside the loop still didn't change the problem

I want all records so I setup the reader as company.datacollector.getreader(sql1, Nothing)
as it wouldn't accept .getreader(sql1) it needed .getreader(sql1, Nothing)

Is that causing the single record

Hope this makes sense
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Reader.getstring(count)  
is incorrect if you get 4 records with 1 field;
if you get 1 record with 4 fields, you shall not "loop" on the Reader.Read, but just do a "Read once", and then loop on the field count
in which case the code would be:
if Reader.read
      do while count < Reader.Columns.Count
         Dim FieldName as Reader.getstring(count)
        count = count + 1
       combobox.items.add(fieldname)
   end loop
end if 

Open in new window

0
 
KevinfeeningAuthor Commented:
Thanks again

Not 1 record with 4 fields 4 records but only getting return of 1 record

What is the code needed to return all 4 records

The table has an Index and a description I need all 4 descriptions
0
 
KevinfeeningAuthor Commented:
Thank you

I hope to be able to use your help again it was excellent
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.