开发者

How to check if row with particular id exists in datatable

开发者_C百科

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜