Solved Reading sql server table

Posted on 2014-09-10
Last Modified: 2014-09-11
Hi Experts

Using while 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
      Dim FieldName as Reader.getstring(count)
     count = count + 1

Thanks for the help
Question by:Kevinfeening
  • 3
  • 3
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)

Expert Comment

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

Author Comment

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40316464
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:
      do while count < Reader.Columns.Count
         Dim FieldName as Reader.getstring(count)
        count = count + 1
   end loop
end if 

Open in new window


Author Comment

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
LVL 142

Accepted Solution

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)

Author Closing Comment

ID: 40316520
Thank you

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now