我有一个由存储过程填充的 DataTable,并且该数据表中包含Requests(RequestNumber and Tasks(TaskId)
. 当我通过任务达到第一个请求编号时,我将它添加到我的列表中,然后使用其他数据行,我检查列表以查看它们是否存在(if(dr["RequestNumber"].ToString() != acList[i].RequestNumber)
)如果存在,我删除数据行,如果不我将它们添加到名单。
这按顺序很好,但如果数据行和列表关闭一个,它允许添加行。是否有任何其他方法可以完成查找该值是否存在于列表中。
提前致谢。
foreach (DataRow dRow in dt.Rows)
{
DataRow dr = dt.NewRow();
dr["Project"] = dRow["Project"];
dr["RequestNumber"] = dRow["RequestNumber"];
dr["RequestId"] = dRow["RequestId"];
dr["TaskType"] = dRow["TaskType"];
dr["TaskId"] = dRow["TaskId"];
dr["TaskStatus"] = dRow["TaskStatus"];
dr["AssignedTo"] = dRow["AssignedTo"];
dr["DateDue"] = dRow["DateDue"];
if (acList.Count == 0)
{
acList.Add(new AssignedClass
{
Project = dr["Project"].ToString(),
RequestNumber = dr["RequestNumber"].ToString(),
RequestId = dr["RequestId"].ToString(),
TaskType = dr["TaskType"].ToString(),
TaskId = dr["TaskId"].ToString(),
TaskStatus = dr["TaskStatus"].ToString(),
AssignedTo = dr["AssignedTo"].ToString(),
DateDue = dr["DateDue"].ToString()
});
}
else
{
for (int i = 0; i < acList.Count; i++)
{
if(dr["RequestNumber"].ToString() != acList[i].RequestNumber)
{
acList.Add(new AssignedClass
{
Project = dr["Project"].ToString(),
RequestNumber = dr["RequestNumber"].ToString(),
RequestId = dr["RequestId"].ToString(),
TaskType = dr["TaskType"].ToString(),
TaskId = dr["TaskId"].ToString(),
TaskStatus = dr["TaskStatus"].ToString(),
AssignedTo = dr["AssignedTo"].ToString(),
DateDue = dr["DateDue"].ToString()
});
}
else
{
dr.Delete();
}
}
}