.NET Framework Developer Center >
Data Platform Development Forums
>
ADO.NET DataSet
>
Typed dataSet Master-Details Table Form Issue
Typed dataSet Master-Details Table Form Issue
- I try to create one form using Typed DataSet. The Form have Detail part and Datagridview .
when I click save first time (CustomerMaster Details,DataGridView display OrderDetails) the Error Displays
Error No: 547
Description: The Insert Statement conflict with the FOREIGN KEY constraint "FK_OrderDetails_CustomerMaster".The conflict occurred in database "Sales",table "dbo.CustomerMaster",Column 'CustomerID.The Statement has been terminated.
Result is CustomerMaster Table save the data but OrderDetails does'nt
Then I Click Add(New) button then try to save new customer and order details then working perfectly.
My SaveButton Code Snippet Is Below
----------------------------------------------------------
Try
Me.validate()
Me.CustomerMasterBindingSource.EndEdit()
Me.CustomerMasterTableAdapter.Update(Me.CustomerDataSet.CustomerMaster)
Me.CustomerOrderTableAdapter.Update(Me.CustomerDataSet.OrderDetails)
Catch ex as Exception
end try
----------------------------------------------------------
Please help
Regards
Saju- Moved byVMazurMVP, ModeratorThursday, November 05, 2009 10:47 AM (From:ADO.NET Data Providers)
- Moved byeryangMSFTThursday, November 05, 2009 2:08 AMwrong forum (From:.NET Base Class Library)
Answers
- Hi Saju,
If you create a new project for this, will the exception occur again?
When you add the datasource of master and details table, you get dataset like this,
Department -- Master Course -- Detail
If you want to manipulate them, you can fist drag the gridview of Department. Then drag the datagridview under the root of Deparment.
The save button's code will be as follows,
this.Validate();
this.departmentBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.sQLServer2005DBDataSet);
In this way, you don't have to deal with the save code manually. Does this work for you?
I guess your problem is probably caused by the update order of the records. If you want to add your own logic of saving, be careful that your code may conflict with the generated code.
You can also refer to this thread for some information,
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/0ba0501d-bc2e-4afc-824e-b75f18a8b491
Best Regards
Yichun Feng
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
- Marked As Answer byYichun_FengMSFT, ModeratorTuesday, November 10, 2009 1:33 AM
All Replies
- Hi Saju,
If you create a new project for this, will the exception occur again?
When you add the datasource of master and details table, you get dataset like this,
Department -- Master Course -- Detail
If you want to manipulate them, you can fist drag the gridview of Department. Then drag the datagridview under the root of Deparment.
The save button's code will be as follows,
this.Validate();
this.departmentBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.sQLServer2005DBDataSet);
In this way, you don't have to deal with the save code manually. Does this work for you?
I guess your problem is probably caused by the update order of the records. If you want to add your own logic of saving, be careful that your code may conflict with the generated code.
You can also refer to this thread for some information,
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/0ba0501d-bc2e-4afc-824e-b75f18a8b491
Best Regards
Yichun Feng
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
- Marked As Answer byYichun_FengMSFT, ModeratorTuesday, November 10, 2009 1:33 AM


