The name of my column in the data table varies

Hello,
I use a for each row in data table and in it an if Row("Name").Contais(reference).
But the name of column in my data table is not always “Name”, it can be “Name/” or “|Name”.
How to use the column containing “Name” in my if?

if Row(“Name/”).Contains(reference) or if Row(“|Name”).Contains(reference)

Thanks, but that will be too complex. “Name/” and “|Name” are only examples, I can have many different possibilities. There would be a solution to do as in SQL where we put % to replace unknown characters?

Hey!

Instead of giving the ColumnName we can give the column index…

For example if our column position is fixed we can do like this…

CurrentRow(0).ToString.Trim

Note: Column index starts with 0

the if condition should like this

CurrentRow(0).ToString.Trim.Contains("reference")

Try this and let me know

Regards,
NaNi

That will fault if one of the column names doesn’t exist.

strCol=(dtTest.Columns.Cast(Of DataColumn).Where(Function ( c ) c.ColumnName.Contains(“Name”)).FirstOrDefault).ToString

This will give you the column name if Name is always present and only present for the column you are looking.

Then you could pass strCol in For Each Row.

1 Like

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