虽然网上有很多DataTable过滤重复行的方法,但是本菜还是认为自己写的这个方法最靠谱,这里的参数是传递的DataTable值,返回的是一个已经过滤相同字段StuId,ExamNum的DataTable,有遇到这个问题的童鞋可以直接拿过去用

DataTable FilterRepeatTable(DataTable table)
{

DataTable _table = table.Clone();
foreach (DataRow row in table.Rows)
{
int rowCount = (from DataRow q in _table.Rows where q["StuID"].ToString() == row["StuID"].ToString() && q["ExamNum"].ToString() == row["ExamNum"].ToString() select q).ToList().Count();
if (rowCount ==0)
{
DataRow _row =_table.NewRow();
_row.ItemArray = row.ItemArray;
_table.Rows.Add(_row);
}
}
return _table;
}

 

相关文章:

  • 2021-12-16
  • 2022-12-23
  • 2021-10-25
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2022-12-23
  • 2022-03-06
  • 2021-09-13
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案