contraint is being violated

lsdev

Well-known member
Joined
Jan 20, 2008
Messages
61
Programming Experience
1-3
Right Basically I have a form with many child table details in it, it all work correctly and updates fine...My issue is that if I delete all the records and try in make a new insert it fails??

Example code:

Me.ParentBindingSource.EndEdit()
Me.ParentTableAdapter.Update(Me.DataSet.Parent)

Me.ChildBindingSource.EndEdit()
Me.ChildTableAdapter.Update(Me.DataSet.Child) <- error occurs here

Me.Child1BindingSource.EndEdit()
Me.Child1TableAdapter.Update(Me.DataSet.Child1)


It is basically giving me a message saying that a contraint is being violated, as in there is no parent? BUT if I open oracle and SELECT * from Parent; The new record is there?? This only happens if it is the first record inserted via my windows form
 
Why do you have 2 instances of Child?


Might I suggest that immediately after you AddNew() you EndEdit(), then when it comes to save, you EndEdit() everything first

Is the Constraint Violated coming from oracle or the data set?
 
Why do you have 2 instances of Child?


Might I suggest that immediately after you AddNew() you EndEdit(), then when it comes to save, you EndEdit() everything first

Is the Constraint Violated coming from oracle or the data set?

Sorry I think you have slightly miss read it, I have a master form with lots of child tables. I have found out the issue is due to an oracle contraint being broken. In that when it comes to here it is saying that teh primary key is being violated:

Me.ChildBindingSource.EndEdit()
Me.ChildTableAdapter.Update(Me.DataSet.Child) <- here

But in oracle the parent record exists?? It's really strange yet it is not happening all the time
 
Er.. violating the primary key of a child table is not the same as violating the relationship between the tables

Parent: OrderID
Child: OrderID, ItemID

You can add the following to the parent:

1
2
3

You can then add the following to the child:

1A
1B
2A
2B
3A
3B

But you cant then add this to the child:

1A

Because 1A already exists.. It violets the child PK, not the relation
 
Er.. violating the primary key of a child table is not the same as violating the relationship between the tables

Parent: OrderID
Child: OrderID, ItemID

You can add the following to the parent:

1
2
3

You can then add the following to the child:

1A
1B
2A
2B
3A
3B

But you cant then add this to the child:

1A

Because 1A already exists.. It violets the child PK, not the relation


I understand that but im using an oracle sequence so this should not happen. I have noticed that if I leave the form and come back of fresh, re-entering the data, the insert works
 
I'd need to look into the update code to be sure..

As a curio, have you written your INSERT statement with a RETURNING INTO clause?
 
What I have done is on .update() for a new record a scalar query is run which returns the nextval for the parent table's sequence. It then populates the ID textbox with this value right before the insert is made. So that after completion I can display in a message box the ID for the record. I dont know if this is the best way of doing this but it was the only way I could find to return the value after an insert
 

Latest posts

Back
Top