Data reader Column Names

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

While i am looping the records how i do for each field name

while(objRead.Read())

foreach(
{
match(x)
Console.WriteLine(objRead.);
}
 
Try using the column name as an indexer ala:

objRead["ColumnName"]

And capture the return value and typecast as needed.

Brendan
 
Thats giving me column name that i would ask for. What i like to achive
is
While i am reading the Reader without knowing what are the column
names, i would like to go thru all the column names and compare with
some variables that i have
so !
while(objRead.Read())
{
foreach loop or something // go thru all the column names
{
if any match = x
{console.writeLine}
}
}
can i do this?
 
...
Thats giving me column name that i would ask for.
What i like to achive is
While i am reading the Reader without knowing what are the column
names, i would like to go thru all the column names and compare with
some variables that i have so !
while(objRead.Read())
{
foreach loop or something // go thru all the column names
{
if any match = x
{console.writeLine}
}
}
can i do this?

Well, I guess you're after something like this...

DataTable myTable = objRead.GetSchemaTable();

while(objRead.Read())
{
foreach(DataRow myRow in myTable.Rows)
{
string colname = myRow["ColumnName"].ToString();

if (matchcondition)
{
// Console.WriteLine or whatever...
}
}
}


// Bjorn A
 
Cant believe there is no GetFieldNames with dataReader.
so i just put them in arraylist if anyone interested.
int a = objRead.FieldCount - 1;
ArrayList lst = new ArrayList();
for(int i=0; i<=a; i++)
{
lst.Add(objRead.GetName(i));
}
 
Back
Top