删除指定的数据表's行
本文关键字:数据表 删除 | 更新日期: 2023-09-27 18:08:47
我已经用父母作为键和他们的孩子作为值的List<>
从DataTable
关系中填充了一个字典,这个关系非常好,每个孩子都被保存为一个名为Definition
的结构,并插入到List<Definition>
structure Definition
{
int id;
int atom;
int id_d
};
但我想要实现的是,在迭代Dictionary<Definitions,List<Definitions>>
上的值列表时,我的意思是,DataRelation
的孩子,我想要删除DataTable
真表中的某些行,这些值是从迭代List<Definitions>
值的Dictionary
中获取的即
Dictionary<Definitions,List<Definitions>> dataRelation;
DataTable parents;
DataTabale children;
foreach(var it in dataRelation)
{
for(int i =0 ; i< it.value.count : i++)
{
if(is the row i want to delete)
{
Children.delete(with the structure's Definition value parameters )
}
}
}
结构体的Definitions
变量与DataTabale
列的名称相同。
我必须承认我真的不知道问题是什么,但我会使用这个可读的方法:
var rowsToDelete = from cRow in children.AsEnumerable()
join r in dataRelation.Values
on new {
id = cRow.Field<int>("id"),
atom = cRow.Field<int>("atom"),
id_d = cRow.Field<int>("id_d")
} equals new { r.id, r.atom, r.id_d }
select cRow;
foreach(DataRow rowToDelete in rowsToDelete)
rowToDelete.Delete();
// now use a dataadapter to actually delete this row from the datasource