Find a value in DataTable

Dhanapal picture Dhanapal · Mar 11, 2009 · Viewed 156.3k times · Source

Is there a way to find a value in DataTable in C# without doing row-by-row operation?

The value can be a part of (a substring of row[columnName].value , separated by comma) a cell in the datatable and the value may be present in any one of columns in the row.

Answer

Andy Rose picture Andy Rose · Mar 11, 2009

A DataTable or DataSet object will have a Select Method that will return a DataRow array of results based on the query passed in as it's parameter.

Looking at your requirement your filterexpression will have to be somewhat general to make this work.

myDataTable.Select("columnName1 like '%" + value + "%'");