Database constraints and dataset constraints

  • Thread starter Thread starter Rapi
  • Start date Start date
R

Rapi

Hello.

I`ve got a problem with constraints. Simple example

Table1
ID
Name
Primary key ID

Table 2
PARENT_ID
Memo
Foreign key-: PARENT_ID=Table1.ID

(as simple as I could)

When I`ve got constraints on database and dataset and delete row then when I
update dataset: first table1 next table2 I`ve got error. When I change
tables then everything is OK.
As I find out this is because when I delete row in dataset table1 then
constraint "deletes" row in table2 (in dataset). When I update table1 then
databse constraint "deletes" row in table2 (on databse) and when I try to
update Table2 I get error -> there are no such rows (constraints on database
clear them).

How to fix this problem?
When I change the order of updating the tables then I`ve got error on update
command when I insert something.
Can`t I use dataset constraints and handling events of deleting rows in
parent table?
 
Hi Rapi,

You should do it in the right order:

1. Delete rows from child to master
2. Insert rows from master to child
3. Update rows (doesn't matter the order) can be placed anywhere

You can extract deleted rows by using
DataRow[] rows = table.Select(null, null, DataViewRowState.Deleted);

The same is true for modifed and added (just change the last parameter).

You should pass the rows array to Update method.
 
Back
Top