Get all the column names From datatable using linkQ query

Heyy i have used this LinkQ query but i m getting error.

dt.Columns.Cast().Select(x => x.ColumnName).ToList()

please somebody correct me where i m wrong

Hi @Tabbu

Refer the Thread below to fetch column name using for each!

Regards

Sorry i cant use foreach i need linQ query

Hi @Tabbu

Use this query to get all columns name

column_names= dt.Columns.Cast(Of DataColumn).Select(Function(m) m.ColumnName.ToString).ToList()

Regards,
Nived N

2 Likes

Thank you @NIVED_NAMBIAR .But i wanyed to know the meaning of the above query and your query is same?

Here i am taking dt.Columns and then casting to DataColumn type and then iterating through each value and picking up the column name from it using the property ColumnName

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