Hi,
I have a datatable with a bunch of rows in it, the first column is an Int32
and I want to perform a simple select like:
select * from MyDataTable where column1 = 234
Hi,
I have a datatable with a bunch of rows in it, the first column is an Int32
and I want to perform a simple select like:
select * from MyDataTable where column1 = 234
if you're talking of a System.Data.DataTable, you can use datatable.Rows.Find for searching a row by primaryKey, or datatable.Select for obtaining a array of rows that satisfy your condition.
// By DataTable's primary key
datatable.Rows.Find(234);
// By compound primary key
datatable.Rows.Find(234, 1, 4);
// by Select
datatable.Select("column1=234");
// by Compound Select
datatable.Select("column1=234 AND column2=1");
Try this to get result as row array :
DataRow[] rows = myDataTable.Select("column1 = 234");
Or this to get dataview :
DataView myDataView = myDataTable.DefaultView;
myDataView.RowFilter = "column1 = 234";
Check out this link:
http://msdn.microsoft.com/en-us/library/b51xae2y(VS.71).aspx
var result = from row in table.AsEnumerable()
where row[0].Equals(42)
select row;
Or
var result = table.AsEnumerable().Where(row => row[0].Equals(42));