andyw27
asked on
Accessing data table column name
Hi,
l have a simple loop that loops through all the rows in a data table. At any point within this loop I need to access the column name?
Can't seem to figure out how this can be done?
Any suggestions?
l have a simple loop that loops through all the rows in a data table. At any point within this loop I need to access the column name?
Can't seem to figure out how this can be done?
Any suggestions?
I need more information about your environment. Is this a VB.NET app? DAO? C? MS Access? Using a particular activex control?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, it depends how do you approach database.
With DataTable you have ColumnName property for each DataColumn
So using DataColumnCollection you could do something like
If you're using (Sql)DataReader just use GetName method, i.e.
Ivo Stoykov
With DataTable you have ColumnName property for each DataColumn
So using DataColumnCollection you could do something like
foreach(DataColumn column in MyDataTable.Columns)
{
Console.WriteLine(column.ColumnName);
}
If you're using (Sql)DataReader just use GetName method, i.e.
var reader = cmd.ExecuteReader();
for(int i=0;i<reader.FieldCount;i++)
{
Console.WriteLine(reader.GetName(i));
}
HTHIvo Stoykov