rpatterson
New member
- Joined
- Sep 15, 2014
- Messages
- 3
- Programming Experience
- 5-10
Hello, been racking my brain on this one for a while now. On my sqlserver 11 i have two tables, tblReconcile and tblReconcile checks. i have relationship defined between the parent and child. Parent has a primary key ReconcileID is a autonumber, IndentityIncrement & Seed set.
View attachment 4090
I have a strong types dataset created with the dataset wizard. The tblReconcile in the dataset tools window shows the child table tblReconcileCheck correctly.
View attachment 4091
i drag over a field from the dataset window, vb creates dataset, bindsource and tableadapter objects. For controls i setup the (databinding) property successfully. For the grid, i drag over the child table from the dataset window, vb creates another bindingsource, BindingSourceReconcileCheck. BindingSourceReconileCheck's datasource is set to ParentBindingSource its datameber set to FK_tblReconcileCheck_tblReconcile. The Child grid for ReconcileChecks is bound to BindingSourceReconileCheck..
Theres and update called:
Me.Validate()
Me.TblReconcileBindingSource.EndEdit()
TblReconcileCheckBindingSource.EndEdit()
TblReconcileTableAdapter.Update(Me.DataSet1)
TblReconcileCheckTableAdapter.Update(DataSet1)
Ok, so it works perfectly when modifying existing records, child follows parent successfully, except when i goto add a new record in the parent and then to the grif. The Grid adds the tempory keys IE -1,-2,-3 etc. Except when i call the above update i get the statement, breaking on "TblReconcileCheckTableAdapter.Update(DataSet1)"
The statement has been terminated. The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblReconcileCheck_tblReconcileDATABASE". The conflict occurred in database "eboxII", table "dbo.tblReconcile", column 'ReconcileID'.
I know this error is coming from sqlsever when its trying to write these tempory keys back to db. Not sure what going wrong here. From what i've read it, the dataset variable is suppose to bring the key value back up.
I used GUID's for years to work around this, but i figured theres a correct way! ANy help is appreicated!
View attachment 4090
I have a strong types dataset created with the dataset wizard. The tblReconcile in the dataset tools window shows the child table tblReconcileCheck correctly.
View attachment 4091
i drag over a field from the dataset window, vb creates dataset, bindsource and tableadapter objects. For controls i setup the (databinding) property successfully. For the grid, i drag over the child table from the dataset window, vb creates another bindingsource, BindingSourceReconcileCheck. BindingSourceReconileCheck's datasource is set to ParentBindingSource its datameber set to FK_tblReconcileCheck_tblReconcile. The Child grid for ReconcileChecks is bound to BindingSourceReconileCheck..
Theres and update called:
Me.Validate()
Me.TblReconcileBindingSource.EndEdit()
TblReconcileCheckBindingSource.EndEdit()
TblReconcileTableAdapter.Update(Me.DataSet1)
TblReconcileCheckTableAdapter.Update(DataSet1)
Ok, so it works perfectly when modifying existing records, child follows parent successfully, except when i goto add a new record in the parent and then to the grif. The Grid adds the tempory keys IE -1,-2,-3 etc. Except when i call the above update i get the statement, breaking on "TblReconcileCheckTableAdapter.Update(DataSet1)"
The statement has been terminated. The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblReconcileCheck_tblReconcileDATABASE". The conflict occurred in database "eboxII", table "dbo.tblReconcile", column 'ReconcileID'.
I know this error is coming from sqlsever when its trying to write these tempory keys back to db. Not sure what going wrong here. From what i've read it, the dataset variable is suppose to bring the key value back up.
I used GUID's for years to work around this, but i figured theres a correct way! ANy help is appreicated!