Solved

Vb.net Reading sql server table

Posted on 2014-09-10
7
304 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 143

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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 143

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 143

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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