Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For..Loop: Stepping through columns and values in a DataReader

Status
Not open for further replies.

DSect

Programmer
Joined
Sep 3, 2001
Messages
191
Location
US
Hello -

I'm trying to figure out how to step through the DataReader when building a "confirmation page" for my app.

Basically - I'd like to see code to Response.Write the Column Name and the Value of that column..

This record set is only one record, with about 8 columns.

In long hand, it would be:

Code:
   ' Open Reader
   dr.Read
   ' Write Column Name
   Response.Write(dr.GetName(0) & "<br>")
   ' Write Column Value
   Response.Write(dr.Item(0) & "<hr>")

   --- Repeat for all columns in the DataReader ---

So, I was wondering what a looped step-though would look like. I often get confused on my loops. I'm guessing that I'm not going to use "FOR...EACH" but rather one with a counter.

Maybe like:
"FOR "blah" to [Count of Columns]"
"Response.Write(dr.GetName(blah))"

Something along those lines? I've very close, I bet, but as a novice, this gets confusing sometimes.

Thanks again!
 
Got it..

Code:
        For x = 0 To (dr.FieldCount - 1)
            (insert code here)
        Next

The field count messed me up for a second. Thanks anyways, all!
 
Code:
   ' Open Reader
   dr.Read
   ' Write Column Name
   Response.Write(dr.GetName(0) & "<br>")
   ' Write Column Value
   Response.Write(dr.Item(0) & "<hr>")

   --- Repeat for all columns in the DataReader ---
Please tell me you are only using Response.Write for this test and you don't intend to display your page by doing this...

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top