Get the column headers from a DataRow object

I am trying to retrieve the column headers from a DataRow object. Searched a few posts but doesn’t solve the problem.

Say
We have a dataRow object called “date” with value {“2021”,“09”,“07”}
Is that possible to retrieve a list of headers like {Year,Month, Day}?

So I can check whether this list contains, say Hour, Minutes or seconds?

Hi @curtis971014

We can take headers from datatable into list like below

dt.columns.cast(of datacolumn).select(function (col) col.columnname.tostring).tolist

Thanks

1 Like

Hi,

Let’s say dr as DataRow.

Then

dr.Table.Columns returns DataColumnCollection

IF you want to get array of column name, the following will work.

dr.Table.Columns.Cast(Of DataColumn).Select(Function(c) c.ColumnName).ToArray

Regards,

1 Like

Great. It works!! Thank you.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.