Extract Column Name from Datatable for some particular condition

I want to check a value inside a Datatable and if that value is found, I want to extract Column Name and value, where that particular value is located. I have used ‘IF’ Condition to check the value “CurrentRow.ItemArray.Contains(“0022218338”)” inside the iterative ‘For each row’ (for datatable) but don’t know how to pull the column name and the value when the value found.


The following will return list of column index number which has the data of the row.

listInt32 = CurrentRow.ItemArray.Select(Function(x,i) if(x.ToString="0022218338",i,-1)).Where(Function(i) i>=0).ToList

And as you use Contains(“0022218338”), value will be just “0022218338”.


Hi @Ashish_Bansal

The below expression would help




So you don’t have fixed column where to look into?


Yes, Column Names are not fixed.

Problem is that I don’t know the column name as it is not fixed.


The following returns list of column name which match the data.

listColumnNames = CurrentRow.ItemArray.Select(Function(x,i) if(x.ToString="0022218338",CurrentRow.Table.Columns(i).ColumnName,"")).Where(Function(s) not String.IsNullOrEmpty(s)).ToList


Thanks. Let me try this.

It worked for me. Many thanks. :slight_smile:

1 Like

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