Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of columns in dataset

Tags:

c#

.net

Is it possible to find the number of columns a data set has?

I know we can find the length of rows with:

ds.Tables[0].Rows.length

Is there something similar for counting or returning the length of the columns?

like image 514
steave Avatar asked Dec 07 '25 23:12

steave


2 Answers

You should look the properties of DataTable before asking this. As it should work.

ds.Tables[0].Columns.Count;
like image 96
Sachin Avatar answered Dec 09 '25 11:12

Sachin


Use the DataTable.Columns.Count property. So ds.Tables[0].Columns.Count.

If you have a DataRow you can also use this property via...

int columnCount = row.Table.Columns.Count;

or another option is the DataRow.ItemArray which contains all fields:

int columnCount = row.ItemArray.Length; 
like image 23
Tim Schmelter Avatar answered Dec 09 '25 12:12

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!