The
Select
method of
DataTable
explained here
http://msdn.microsoft.com/en-us/library/b5c0xc84.aspx[
^]
can be used to filter the
Rows
of the
DataTable
as follows:
DataRow[] rows = items.Select("Item_Code ='BO97'",string.Empty, DataViewRowState.CurrentRows);
The second parameter can be used to
Sort
the rows returned by the method.
The
Select
method returns an
Array
of
DataRows
. Hence all
Columns
of
DataTable
are automatically present in the returned rows.
It is preferable to use
DataViewRowState.CurrentRows
as the third argument to the method, so that it will not return the
rows
which have been deleted by
Row.Delete()
method. Otherwise, it returns these rows also and while performing an operation on these rows an error will be thrown.
If the single row is required if found then
if (rows.Length > 0)
Alternatively, the DataView can be used
DataView itemsView = items.DefaultView();
itemsView.RowFilter= "Item_Code='BO97'";
if itemsView.Count > 0 then