473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Data reader Column Names

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
5 2984
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
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
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
"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
Yeap that will do.
Thanks $mil

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Stephan | last post by:
I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd...
1
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
2
by: Joe Campbell | last post by:
I have a DBA that wrote a stored procedure that does a SELECT from a particluar SQL Server table. Within that stored procedure he links over to grab a column from another database table. I need to...
1
by: paul_zaoldyeck | last post by:
Good Day everyone!!! i have here a serious problem.my project is delayed because of this. i'm trying to make a function for an XML Reader that accepts values from the other modules(done by the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.