Updating database with changes in dataset

G

Guest

Hello all, I've made a dataset by using the xsd tool in C#. In the xsd
schema, there are a few tables, each has its own primary key. And, I've made
relation between them.

After all things are done, I can use the dataset class generated to retrieve
data. The problem is that, when I try to delete a parent row (using
RemoveTABLERow method), both the parent and child tables rowcount decrease as
expected. But only the changes done in child table can be updated to the DB.
The parent row is still there.

I've tried the sequence suggested by MSDN:
1. Child table: delete records.
2. Parent table: insert, update, and delete records.
3. Child table: insert and update records.

Sometimes nothing changed in DB. Sometimes only child table show changes.

Could anyone give me any hint what I should do to fix the situation?
 
D

Dmytro Lapshyn [MVP]

Hi,

Can you please post some code? Meanwhile, please make sure you properly
configure Insert/Update/DeleteCommands on all of the data adapters and that
you never call AcceptChanges before calling Update() on the data adapters.
 
G

Guest

Thx much, Dmytro.

I realized that I've used the wrong function to delete the row in my
dataset. Now I can do what I want.

However, if I load data from more than 10 tables (say, a few rows per
table), all are linked up by parent-child relations. My update functions must
be arranged very carefully in a particular order (Child table row deletion
first...). Is that correct?

Are there any easier way to deal with updating the DB?

Thanks again.

Dmytro Lapshyn said:
Hi,

Can you please post some code? Meanwhile, please make sure you properly
configure Insert/Update/DeleteCommands on all of the data adapters and that
you never call AcceptChanges before calling Update() on the data adapters.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Kenny said:
Hello all, I've made a dataset by using the xsd tool in C#. In the xsd
schema, there are a few tables, each has its own primary key. And, I've
made
relation between them.

After all things are done, I can use the dataset class generated to
retrieve
data. The problem is that, when I try to delete a parent row (using
RemoveTABLERow method), both the parent and child tables rowcount decrease
as
expected. But only the changes done in child table can be updated to the
DB.
The parent row is still there.

I've tried the sequence suggested by MSDN:
1. Child table: delete records.
2. Parent table: insert, update, and delete records.
3. Child table: insert and update records.

Sometimes nothing changed in DB. Sometimes only child table show changes.

Could anyone give me any hint what I should do to fix the situation?
 

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