How to check if row with particular id exists in datatable
I have two datatable, while adding rows in second datatable, I want to first check whether the id in the second datatable matches as in the first datatable, if not only then it should be added in the second datatable, else it should display a message.
Please note, I don't have any Primary Key defined on any column, so the rows could be repetitive.
if (datatable2.Select("columnname = " + datatable1.Rows[0]["columnname"]).Length > 0)
{
// row exist in table2
}
else {
// does not exist in table2
}
For more information http://msdn.microsoft.com/en-us/library/det4aw50.aspx
精彩评论