Hello:
I am trying to get the name of the column in the datareader in a for/loop. I can get the value of the column, but I also need the name. What do I have wrong or how can I get it?
for (int i = 0; i < ClassDB.DBDataReader.FieldCount - 1; i++)
{
//TheColumnName = ClassDB.DBDataReader....????
TheColumnValue = ClassDB.DBDataReader[i].ToString();
MessageBox.Show("i=" + i + " TheColumnName=" + TheColumnName + " TheColumnValue=" + TheColumnValue);
}
How Do I: Get the column name from a datareader?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

GustavoRank #1,990 · 732 reputationPosted May 22, 2010, 10:11 AM EDT
This is the line I needed.
TheColumnName = ClassDB.DBDataReader.GetName(i);
BTW: Can someone tell me how I can flag my post as answered?