Saturday, March 24, 2012

Loop through DataReader

I need to know how to loop through all the elements in each row of a DataReader.

For example,

myDataReader.Read();
foreach(whattype? i in myDataReader) {
Response.Write(myDataReader[i]+"<br>");
}

I would like to do it this way because I do not know the name of the items in each row.

Thanks!Take a look at the FieldCount property.

Example:


for (i=0; i < myDataReader.FieldCount; i++)
{
Response.Write(myDataReader[i] + "<br>");
}

Thanks!

How would you get the Key?

myDataReader[i] gives you just the value.

??

James

0 comments:

Post a Comment