How to get information from deleted rows. I deleted several rows from the table in the dataset, then I use the GetChanges (DataRowState.Deleted) method to get deleted rows. I tried deleted rows in the source table on the server side, but ended up with these errors.
System.Data.DeletedRowInaccessibleException: information about the deleted row could not be accessed through the row.
What is right? Here is my code, any advice? Thanks to everyone.
Dataset ds =
DataTable delRows = ds.Tables[0].GetChanges(DataRowState.Deleted);
if (delRows != null)
{
string connStr = WebConfigurationManager.ConnectionStrings["Employees"].ConnectionString;
conn = new SqlConnection(connStr);
conn.Open();
for (int i = 0; i < delRows.Rows.Count; i++)
{
string cmdText = string.Format("DELETE Tab1 WHERE Surname=@Surname");
cmd = new SqlCommand() { Connection = conn, CommandText = cmdText };
var sqlParam = new SqlParameter(@"Surname", SqlDbType.VarChar) { Value = delRows.Rows[i][1].ToString() };
cmd.Parameters.Add(sqlParam);
cmd.CommandText = cmdText;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
source
share