iterating thru a datareader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
i want to loop thru my datareader to get all the fieldnames, what's the best
way to do this?

thanks,
rodchar
 
rodchar,

You can use the FieldCount property, along with the GetName method, like
so:

// Create an array of strings for the field names.
string[] fieldNames = new string[reader.FieldCount];

// Populate.
for (int index = 0; index < reader.FieldCount; ++index)
{
// Set the name.
fieldNames[index] = reader.GetName(index);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top