How can I retrie infromation from delete rows. I delete some rows from table in dataset, then I use method GetChanges(DataRowState.Deleted) to get deleted rows. I try delete rows in original table on server side, but it finished with this errors. I try get
value of columns from row, which was deleted
System.Data.DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.
What is correct way? Here is my code, any advice? Thank you everybody
Dataset ds = //get dataset from client side
//get changes
DataTable delRows = ds.Tables[0].GetChanges(DataRowState.Deleted);
//try delete rows in table in DB
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 };
//here is problem, I need get surnames from rows which was deleted
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();
}
}
After getting the datatable, I guess the original rowstate doesn't change, and you can't get a row value from a deleted row - you can debug and check it. If so, you may try to reset the rowstate and try again. Alternatively, you can save the deleted rows
before deleting as suggested above.
Please let us know with details if you still can't resolve the problem.
Thanks.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Hi, the scenario is. Client call ASP.NET web service and get dataset. Client can delete, modified and add rows to the dataset. After he finish work, he send dataset changes on web service.
Dataset datasetFromWS = proxy.GetDataset();
//he delete some rows from dataset
//finish work
//get changes
DataSet changedDataset = datasetFromWS.GetChanges();
//send datset changedDataset to web service
proxy.SendDataSet(changedDataset);
On service side I try get info which rows was deleted.
[WebMethod]
public bool SendDataSet(DataSet ds)
{
//get info which rows was deleted
DataTable delRows = ds.Tables[0].GetChanges(DataRowState.Deleted);
//and I want delete rows in table in DB by value in deleted rows
//delete in table where column Id = delRows.Rows[i][1].ToString()
}
But this delRows.Rows[i][1].ToString() don't work
it finish with error :
System.Data.DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.
Based on your description, I can see that you're trying to get the row ID to delete the row in database in order to update all the changes, right? Since you couldn't get the row value from the deleted row, can you use another way to submit the changes?
As I know, you may get help of SqlCommandBuilder class to automatically get the changes in dataset and submit them. In this way, you'll have no need to check it one by one manually. Please check a simple sample of SqlCommandBuilder here:
Martin.Lukas
Member
5 Points
46 Posts
how to retrieve information from deleted row
Apr 07, 2010 09:39 AM|LINK
How can I retrie infromation from delete rows. I delete some rows from table in dataset, then I use method GetChanges(DataRowState.Deleted) to get deleted rows. I try delete rows in original table on server side, but it finished with this errors. I try get value of columns from row, which was deleted
DataSet
reza141414
Participant
1571 Points
497 Posts
Re: how to retrieve information from deleted row
Apr 07, 2010 03:44 PM|LINK
how u delete the rows?
i mean how u specify wich row(S) should be deleted?
is it necessary for u to use DataSet and DataTable?
dont forget to mark as answerd...
gianthornet
Member
353 Points
100 Posts
Re: how to retrieve information from deleted row
Apr 08, 2010 09:35 AM|LINK
Hi, I suggest that you should create another table where the deleted data will be saved first before deleted, or make it a log data.
Somehow, you will need that old data in the future.
Martin.Lukas
Member
5 Points
46 Posts
Re: how to retrieve information from deleted row
Apr 08, 2010 02:12 PM|LINK
Hi I specify row, which must be deleted by value of column var value = delRows.Rows[i][1].ToString(), an I delete row in table where Id =value;
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: how to retrieve information from deleted row
Apr 09, 2010 07:11 AM|LINK
Hi Martin.Lukas,
After getting the datatable, I guess the original rowstate doesn't change, and you can't get a row value from a deleted row - you can debug and check it. If so, you may try to reset the rowstate and try again. Alternatively, you can save the deleted rows before deleting as suggested above.
Please let us know with details if you still can't resolve the problem.
Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Martin.Lukas
Member
5 Points
46 Posts
Re: how to retrieve information from deleted row
Apr 09, 2010 09:21 AM|LINK
Hi, the scenario is. Client call ASP.NET web service and get dataset. Client can delete, modified and add rows to the dataset. After he finish work, he send dataset changes on web service.
On service side I try get info which rows was deleted.
[WebMethod] public bool SendDataSet(DataSet ds) { //get info which rows was deleted DataTable delRows = ds.Tables[0].GetChanges(DataRowState.Deleted); //and I want delete rows in table in DB by value in deleted rows //delete in table where column Id = delRows.Rows[i][1].ToString() }But this delRows.Rows[i][1].ToString() don't work
it finish with error :
System.Data.DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: how to retrieve information from deleted row
Apr 12, 2010 02:45 AM|LINK
Hi Martin.Lukas,
Based on your description, I can see that you're trying to get the row ID to delete the row in database in order to update all the changes, right? Since you couldn't get the row value from the deleted row, can you use another way to submit the changes?
As I know, you may get help of SqlCommandBuilder class to automatically get the changes in dataset and submit them. In this way, you'll have no need to check it one by one manually. Please check a simple sample of SqlCommandBuilder here:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx
You can also do some research if you want to know more details.
Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Deependra
Member
16 Points
3 Posts
Re: how to retrieve information from deleted row
Feb 22, 2013 01:47 PM|LINK
Try
delRow.RejectChanges()
It will show you all row related informations .