我有一个有3行的数据表。我正在删除第二行,并试图在代码下面触发以提交数据库。
//code to delete
DataSet.Tables[TableName].Rows[Index].Delete();
//Code to commit in data base
IDbCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "DeleteFromTable";
command.CommandType = CommandType.StoredProcedure;
command.Transaction = tran;
SqlCommandBuilder.DeriveParameters((SqlCommand)command);
((IDataParameter)command.Parameters[0]).SourceColumn = "OrderNumber";
((IDataParameter)command.Parameters[1]).SourceColumn = "ID";
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.UpdateCommand = (SqlCommand)updateCommand; // Working correctly
adapter.DeleteCommand = (SqlCommand)command;
return adapter.Update(dataSet, strTableName);
这会抛出异常:
此行已从表中删除,但没有任何数据。 BeginEdit()将允许在此行中创建新数据。
任何人都知道为什么会这样?