Get number of columns, each column name from a DataRow

Hi, how do I get the number of columns from a DataRow object?

Also, how do I get the column names? Thanks

Hi @DEATHFISH

Try this out and see whether it works for you…

How to retrieve headers of a dataRow element

Let know how it goes

1 Like

Hi @DEATHFISH,

If you have a datarow object then you can use itemarray method

datarowobject.itemarray.count.tostring

The above expression will give number of values in that row, the same number represents the number of columns also.

For extracting column names you can use the below linq query

Refer the below linq query to extract column names from datatable

(From dc In dt.Columns.Cast(Of DataColumn)
Select dc.ColumnName).ToArray()

Refer the post for more reference.

1 Like

Hi, I don’t have a DataTable, only a DataRow, how do I extract the column names from this DataRow?

Hi @DEATHFISH

Use for each,

For each item in Datarowobject.Table.columns and the type argument is “System.Data.Datacolumn”

Inside for each use a write line with item.columnname

1 Like

@anil5

Hi, how do I retrieve the cell content as well inside this for each loop?

Hi @DEATHFISH,

Column value or row value

Column value you can get using above post and row value you can extract using datarowobject.itemarray