DataAdapter.Update(DataSet)

D

dm_dal

I'm sure i've just overlooked something obvious, or, could this be the way
it was designed?

I've got a Strongly-Typed DataSet with three tables, two of the tables are
children of the same parent (relationships are defined). Let's call them
TableParent, TableChild1, and TableChild2.

Now, when I change a value in one of the child tables, I'm commiting the
changes to the db by calling the Update method of the specific DataTable's
DataAdapter. example:

da_ParentTable.Update(MyDataSet);
da_TableChild1.Update(MyDataSet);
da_TableChild2.Update(MyDataSet);

I would think that if no data has changed in TableChild2, then nothing would
be saved to that table, but apparently I'm wrong. What I'm seeing is that
if any of the tables change, then it's matching parent and sibling tables
are being marked as updated and the DataAdapter is trying to save those rows
as well. This causes problems in my case. How do I make sure that only the
rows that were actually modified, get updated in the DB?

dmy
 
D

David Browne

dm_dal said:
I'm sure i've just overlooked something obvious, or, could this be the way
it was designed?

I've got a Strongly-Typed DataSet with three tables, two of the tables are
children of the same parent (relationships are defined). Let's call them
TableParent, TableChild1, and TableChild2.

Now, when I change a value in one of the child tables, I'm commiting the
changes to the db by calling the Update method of the specific DataTable's
DataAdapter. example:

da_ParentTable.Update(MyDataSet);
da_TableChild1.Update(MyDataSet);
da_TableChild2.Update(MyDataSet);

I would think that if no data has changed in TableChild2, then nothing would
be saved to that table, but apparently I'm wrong. What I'm seeing is that
if any of the tables change, then it's matching parent and sibling tables
are being marked as updated and the DataAdapter is trying to save those rows
as well. This causes problems in my case. How do I make sure that only the
rows that were actually modified, get updated in the DB?

Most DataAdapters have an Update(DataTable) method. Try That.

David
 
D

dm_dal

I've tried that...

public void saveData( myTypedDataSet myDataSet)
{
try
{
DataTable parentDataTable = myDataSet.TableParent.GetChanges();
DataTable child1DataTable = myDataSet.TableChild1.GetChanges();
DataTable child2DataTable = myDataSet.TableChild2.GetChanges();

da_ParentTable.Update(parentDataTable);
da_TableChild1.Update(child1DataTable);
da_TableChild2.Update(child2.DataTable);

parentDataTable.Dispose();
child1DataTable.Dispose();
child2.DataTable.Dispose();
}
catch(Exception e)
{
......
}
}

This still saves (in this instance) 1979 rows per table into my database.
Although, by using the ColumnChanged event for each table, I'm capturing the
changes (Original and Proposed) values and dumping them to a seperate table
for reporting. The changes table only reports 97 rows were changed in
TableChild2, but calling GetChanges returns 1979 rows.

dmy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top