繁体   English   中英

DataRow在DataGridView中删除并附加到C#中的DataTable?

[英]DataRow Deleting in DataGridView and attaching to DataTable in C#?

我正在DataGridView中删除一行,并且此Datgridview绑定到数据表(dt)。 删除行后。 数据表中该行的数据被删除并显示错误。

有几种方法可以完成此操作。 一种快速的方法是从修改后的数据表(删除后的数据表)中创建一个数据视图实例,然后在该数据视图上调用ToTable()方法。 这将为我们提供原始数据。

DataView view= new DataView(yourTable, null, null, DataViewRowState.Deleted);
DataTable resultTable = view.ToTable();

另一种方法是

var rows=YourTable.Select(); // I assume your name of the table as YourTable and you can change it the way you want

foreach(var row in rows)
{
  if (row.RowState == DataRowState.Deleted)
{
   var splr_Cntctnm = (string)row["splr_Cntctnm", DataRowVersion.Original];
   //you can access all deleted field information as above
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM