Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a value in DataTable

Tags:

c#

datatable

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.

like image 639
Dhanapal Avatar asked Mar 11 '09 09:03

Dhanapal


People also ask

How do you find the value of a DataTable?

You can loop over each row of the DataTable and check the value. Alternatively you can use a PrimaryKey for your DataTable . This helps in various ways, but you often need to define one before you can use it.

How do I trigger a DataTable search?

var table = $('#myTable'). DataTable({ responsive: true, serverSide: true, ajax: { url: myUrl, dataSrc: '' }, fnServerData: function (sSource, aoData, fnCallback, oSettings) { oSettings. jqXHR = $. ajax({ url: myUrl, success: function (json, status, xhr) { //Do stuff } }); } });


1 Answers

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 + "%'"); 
like image 100
Andy Rose Avatar answered Sep 21 '22 10:09

Andy Rose