By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Data reader Column Names

P: n/a
While i am looping the records how i do for each field name

while(objRead.Read())

foreach(
{
match(x)
Console.WriteLine(objRead.);
}

Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Try using the column name as an indexer ala:

objRead["ColumnName"]

And capture the return value and typecast as needed.

Brendan
"Matt" wrote:
While i am looping the records how i do for each field name

while(objRead.Read())

foreach(
{
match(x)
Console.WriteLine(objRead.);
}

Nov 17 '05 #2

P: n/a
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?

Nov 17 '05 #3

P: n/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));
}

Nov 17 '05 #4

P: n/a
"Matt" wrote...
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
Nov 17 '05 #5

P: n/a
Yeap that will do.
Thanks $mil

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.