I am using C# 2.0, and I can’t help but think this isn’t the most efficient way to search a collection (in this case a DataTable) for a value:
bool found = false; foreach (DataRow row in data.Rows) { if (id == row['rowID']) { found = true; break; } } if (!found) { //Do stuff here }
Can anyone think of a ‘cleaner’ way to do this?
Look at the datatable’s
Select()method:http://msdn.microsoft.com/en-us/library/b5c0xc84(VS.80).aspx