Get All Column index values

I have a Datatable which consists of Columns like Description1,Description2 & Description3… and there is no limit on number of Columns.
I need to get the column index of all these columns if the Column Name Contains Description.

Hi @balarajesh.p

Try this
DT.Columns(“[ColumnName]”).Ordinal

Hi,

I need to get the column index of all these columns if the Column Name Contains Description.

Can you try the following expression?

arrColumnIndex = dt.Columns.Cast(Of DataColumn).Select(function(c,i) if(c.ColumnName.Contains("Description"),i,-1)).Where(Function(i) i>=0).ToArray

Regards,

as an variation:

arrColumnIndex = dt.Columns.Cast(Of DataColumn).Where(Function (c) c.ColumnName.Contains("Description")).Select(Function(x) x.Ordinal).ToArray

and compacted to Query Syntax:

(From c in dt.Columns.Cast(Of DataColumn)
Where c.ColumnName.Contains(“Description”)
Select i=c.Ordinal).ToArray

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