How I can filter a dataTable with Linq to datatable?
You are better of using DataTable.Select
method, but if you have to use LINQ then you can try:
DataTable selectedTable = tb.AsEnumerable()
.Where(r => r.Field<string>("Modul") == value)
.CopyToDataTable();
This would create a new DataTable
based on filtered values.
If you use DataTable.Select
string expression = "Modul =" + value;
DataRow[] selectedRows = tb.Select(expression);
You can use condition to check rows exist in addition before casting. System.Linq namespace is required for Any() to work
var rows = values.AsEnumerable().Where
(row => row.Field<string>("Status") == action);//get the rows where the status is equal to action
if(rows.Any())
{
DataTable dt = rows.CopyToDataTable<DataRow>();//Copying the rows into the DataTable as DataRow
}