Reputation: 1016
I dont know what to keep the heading (still confused, sorry for that). In my project, I am trying to update the database table through DataSet
. Well I achieved this but when I delete any row in my DataSet
and try to update the Database table then VS is showing error --> "Deleted row information cannot be accessed through the row". Then I searched in Internet I got the solution in this answer. Now my code is not showing any error but to my exclamation the database is being updated with new values of DataSet
both existing and deleted too. I dont want to add the deleted rows of Dataset
to database table. How to solve this?
In my code I am using DataRowVersion.Original
, should I change it? I also tried other values of DataRowVersion
but no result.
Upvotes: 1
Views: 238
Reputation: 44
//yes before inserting values into database you have to put some check
foreach (DataRow row in ds.Tables["Table_Name"].Rows)
{
if (row.RowState != DataRowState.Deleted)
{
if (row.RowState == DataRowState.Added)
{
// Perform insertion in to database
}
if (row.RowState == DataRowState.Modified)
{
// perform updation in to databse
}
}
}
Upvotes: 1