我有2个数据表与数据(dtm和dtl)。我必须找出是否存在DataTable1中的Datatable2中的DataRow。我有一个3列的组合主键。我知道我可以像这样得到DataTable primarykey。
DataColumn[] pkcol;
pkcol = dtm.PrimaryKey;
有可能像这样使用查找方法吗?
if (dtl.Rows.Find(dtm[pkcol]) == null)
{
}
我必须实现一个数据表同步方法。所以我在dtm中找到每个Datarow。row和Foreach Datarow中的dll .Rows。这将是伟大的,如果我可以继续在表和搜索,如果存在表中的datarow主键值。什么好主意吗?请帮助。由于
根据MSDN DataRowCollection.Find
已经在寻找PKs中给定值的行。因此,您甚至不需要获得PKs,而只需获得与PKs在数量和类型上匹配的值数组:
// Create an array for the key values to find.
object[]findTheseVals = new object[3];
// Set the values of the keys to find.
findTheseVals[0] = "John";
findTheseVals[1] = "Smith";
findTheseVals[2] = "5 Main St.";
DataRow foundRow = table.Rows.Find(findTheseVals);
您可以将值设置为null来查找您的行。