Solved

Vb.net Reading sql server table

Posted on 2014-09-10
7
302 Views
Last Modified: 2014-09-11
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
0
Comment
Question by:Kevinfeening
  • 3
  • 3
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40316291
>Dim FieldName as Reader.getstring(count)
is likely
Dim FieldName as String = Reader.getstring(0)
0
 
LVL 2

Expert Comment

by:Akilandeshwari N
ID: 40316293
Declare the variable FieldName outside the loop
0
 

Author Comment

by:Kevinfeening
ID: 40316447
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40316464
>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
 

Author Comment

by:Kevinfeening
ID: 40316510
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
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40316512
then you really need to do this, to get the first column of each record:
Dim FieldName as String = Reader.getstring(0)
0
 

Author Closing Comment

by:Kevinfeening
ID: 40316520
Thank you

I hope to be able to use your help again it was excellent
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question