我试图让所有存在于 ALLDATA
的行,但不是在 removeData
公共静态数据表RemoveDuplicateRows(数据表ALLDATA,
数据表removeData)
{
removeData.Merge(ALLDATA);
数据表newData = removeData.GetChanges();
removeData.RejectChanges();
返回newData;
}
removeData 优先于空在这种情况下,调用(只是一个新的DataTable();)
但 newData 总是空的
数据表newData = removeData.GetChanges后的值();
行
最终解决方案:
公共静态数据表RemoveDuplicateRows(数据表ALLDATA,数据表removeData)
{
数据表重复= allData.Clone();
的foreach(DataRow的行allData.Rows)
{
duplicate.ImportRow(行);
}
的foreach(DataRow的行duplicate.Rows)
{
row.SetAdded();
}
removeData.Merge(一式两份);
数据表newData = removeData.GetChanges(DataRowState.Added);
removeData.RejectChanges();
allData.RejectChanges();
返回newData;
}
解决方案
您 removeData 数据表需要有相同的列/为
ALLDATA 。换句话说,它不能只是一个新的DataTable()。
I am trying to get all the rows that exist in allData
but not in removeData
public static DataTable RemoveDuplicateRows(DataTable allData,
DataTable removeData)
{
removeData.Merge(allData);
DataTable newData = removeData.GetChanges();
removeData.RejectChanges();
return newData;
}
removeData
is empty prior to the call in this case (just a new DataTable();)
But newData
always has a value of null after the DataTable newData = removeData.GetChanges();
line
Final Solution:
public static DataTable RemoveDuplicateRows(DataTable allData, DataTable removeData)
{
DataTable duplicate = allData.Clone();
foreach (DataRow row in allData.Rows)
{
duplicate.ImportRow(row);
}
foreach (DataRow row in duplicate.Rows)
{
row.SetAdded();
}
removeData.Merge(duplicate);
DataTable newData = removeData.GetChanges(DataRowState.Added);
removeData.RejectChanges();
allData.RejectChanges();
return newData;
}
解决方案
Your removeData
DataTable needs to have the same columns/fields as allData
. In other words, it can't just be a new DataTable().
上一篇:如何调试的LINQ to SQL InsertOnSubmit声明?声明、to、LINQ、InsertOnSubmit
下一篇:NullReferenceException异常Linq中调用InsertOnSubmit时的Sql异常、NullReferenceException、Linq、Sql