[英]How to delete row in DataTable
foreach(DataRow row in dt.Rows)
{
if (row["ProductID"].ToString().Equals(txtBarcode.Text.Trim()))
{
row.Delete();
txtBarcode.Clear();
}
}
adapt.SelectCommand.Parameters.AddWithValue("@idText", txtBarcode.Text);
adapt.Fill(dt);
dgItems.ReadOnly = true;
dgItems.DataSource = dt;
txtBarcode.Clear();
I am using this code to delete row when user try to insert the same barcode when it exist in the gridview, however there is an error. 当用户尝试在gridview中存在相同的条形码时,我使用此代码删除行,但是出现错误。 at first when i entered duplicate barcode it delete the row but when i entered another duplicate barcode it says
An unhandled exception of type System.Data.DeletedRowInaccessibleException' occurred in System.Data.dll
首先,当我输入重复的条形码时,它会删除该行,但是当我输入另一个重复的条形码时,它说
An unhandled exception of type System.Data.DeletedRowInaccessibleException' occurred in System.Data.dll
Additional information: Deleted row information cannot be accessed through the row.
foreach(DataRow row in dt.Rows)
{
if (row["ProductID"].ToString().Equals(txtBarcode.Text.Trim()))
{
row.Delete();
txtBarcode.Clear();
}
}
dt.AcceptChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.