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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
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)

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

LVL 143

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 143

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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach 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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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