Datatable header names

Hi everyone

I have a data table that I got from excel and when I’m trying to read the header name and check if it contains a specific value (using this method:" DT.Column(0).ColumnName.Contains(value)") it says that it’s not and when I saw the header name it showed me this Column0
and in my excel file, the header has names like Scenario, NumScenario, ModelCode, etc…
PLEASE HELP ME
thank u

@dlichtenstadt
Do not use contains it will take all the column headers which have scenario word in it, Use either “=” operation or like “scenario” or regex operations

You can use below to get all the column names and store it into an array and then check as explained above

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

1 Like

OK I will change that
but it still gives me not the name that in there, like scenario
it gives me Column0

@dlichtenstadt

I have edited above post, please use the linq query given and let me know

I’m sorry I just saw that my read range is without “add headers”, now its working.
and I don’t have any headers that is a duplicate or contains some of another column…
thank u for the help anyway

1 Like

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