Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable.Select() not working

In my datatable I have two rows with multiple columns.

One of the columns are ItemID and their values are 2215,2216.

When I use the following statement:

DataRow[] dr = dt.Select("ItemID='2215'");

It returns both rows. It's not filtering.

What I am missing?

like image 384
Singaravelan Avatar asked Feb 14 '23 06:02

Singaravelan


2 Answers

This should work if your table has data with the structure you described.

var dr = from row in dt.AsEnumerable()
    where row.Field<int>("ItemID") == 2215
    select row;

DataTable dtSelected = dr.CopyToDataTable();
like image 164
Neeraj Kumar Gupta Avatar answered Feb 23 '23 15:02

Neeraj Kumar Gupta


Try like this

DataRow[] dr = dt.Select("ItemID=2215");
like image 29
Nagaraj S Avatar answered Feb 23 '23 16:02

Nagaraj S