Sqldataadapter.update() Not Updating When Rowstate = Modified
I am trying to set up a program that, when a user updates an item description, will update the database upon the save of the form. I have set up everything I have found that is req
Solution 1:
I figured out what I was doing wrong. I was using a table that had a null reference as its original row value and when the SQLDataAdapter.Update() ran it was looking for a row with a null value which did not exist and therefore was ignored. To fix this I changed my "Item" table logic as follows:
ItemsAdapter.AcceptChangesDuringUpdate = true;
foreach ( DataRowRowinItems.AsEnumerable() )
{
if ( !_Items.TableContains("Item", Row["Item"]) )
{ ItemsTable.Rows.Add(Row); }
elseif ( _Items.TableContains("Item", Row["Item"]) )
{
ItemsTable.AsEnumerable()
.Join(Items.AsEnumerable(), r1 => r1.ItemArray[0], r2 => r2.ItemArray[0], (r1, r2) =>new { r1, r2 })
.ToList()
.ForEach(i => i.r1.SetField(1, i.r2.ItemArray[1]));
}
}
ItemsAdapter.Update(ItemsTable);
This change set the new table passed to the update method to update my internal DataTable that had the database values in it to the new update and then used that to update the database and it worked properly.
Hope this may help anyone who may end up with the same issue I had.
Post a Comment for "Sqldataadapter.update() Not Updating When Rowstate = Modified"