Get Column Name from a DataSet

C

C. Antonio

Hello,
I was wondering if anyone knows how to get a column name from a dataset
where the column name contains nulls. I am able to get a columns name using
getxml() however columns that have null's do not return the name of the
column in the xml.

Basically I want the dataset to return columns names even if the column
names contain null values.

thanks guys.
 
C

C. Antonio

Thanks for the quick response Ryan, however this is what is happening:

There are two situation:

1.---- When table does not have any rows, the dataset.getxml() does not
return any column names This is what we are doing like you had in the first
scenario:

DataSet.Tables[TableIndex].Columns[ColumnIndex].ColumnName;



2. -- When the table has rows in it, the dataset.getxml() returns only
columns which has data.

In this scenario we are running two loops to get the column names

Here is what we are doing in the second scenario

for (int lrow = 0; lrow <= ds.Tables[0].Rows.Count - 1; lrow++) {

for (int lcol = 0 ; lcol <= ds.Tables[0].Columns.Count - 1; lcol++)

{

colname = ds.Tables[0].Columns[lcol].ColumnName;

colvalue= ds.Tables[0].Rows[lrow][colname].ToString();

}

}

Is there a single way of doing both scenarios?

William Ryan eMVP said:
DataSet.Tables[TableIndex].Columns[ColumnIndex].ColumnName;

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
C. Antonio said:
Hello,
I was wondering if anyone knows how to get a column name from a dataset
where the column name contains nulls. I am able to get a columns name using
getxml() however columns that have null's do not return the name of the
column in the xml.

Basically I want the dataset to return columns names even if the column
names contain null values.

thanks guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top