First,
tostring()
should be
ToString()
. Second, you should be using a lambda expression. The following code should work (may need some massaging) as long as you previously verified that the
KEY
and
COLUMN_NAME
columns exist in the dataset.
var rows = datatable.Rows.Where(x => x.GetInt32("KEY") == SKEY &&
x.GetString("COLUMN_NAME") == item[0].ToString());
You'll end up with an
IEnumerable
collection of
DataRow
items that meet the specified criteria, or a null result if no matches were found.
I personally don't like working directly with datatables, and instead prefer to move the datatable contents into a list of strongly typed objects because things are much more controllable that way. But that's just me.
Finally, try to avoid using SQL reserved words (such as
KEY
) for column names. It doen't really hurt anything, but it's bad practice.