We help IT Professionals succeed at work.

How do you loop through the columns of a DataReader?

FatalErr
FatalErr asked
on
1,818 Views
Last Modified: 2012-05-05
Here's what I'm basically using

With DataReader
  do while .Read = true

--What can I do instead of the following 3 lines that don't work???
    For each .item as string in DataReader  
       MyString = MyString & Item.ToSTring
    Next
                                             

  console.WriteLine(MyString)
  loop
end With
Comment
Watch Question

Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I appreciate your suggestion.  Though I've done it this way before and should have said so.  I'm trying to learn  how to work with the colulmns in a DataReader in some other way such as For Each or with GetEnumerator that will give other features.

Thanks,
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
I don't think there is a way to iterate the columns of a DataReader the way you are trying to do.  The DataReader class doesn't expose its columns the way a DataTable or DataGridView does.  Explore the properties of the DataReader class, and you'll see they all relate to the reader's current data row or to the reader in general.  The only properties and methods involving columns are the FieldCount property and the Item property, but neither of these allow you to access the columns directly.  (FieldCount only returns an Integer, and Item(i) returns the actual data at the current row in column (i), but not the column itself.)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.