Click here to Skip to main content
15,037,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code thought to insert related datarows to dataset(of cause i use typeddataset because it easier and brings addtional functionalities)

1 assign value to parentdatarow and childdatarow
parentdatarow=some value;
childdatarow=some other value;

2 establish relationship base on their relation

3 using adaptermanager.updateall(dataset) to update 2 inserted datarow

here is the result:

when the daptermanager.updateorderoption is insertupdate,error occur,
because parentdatarow should exist before its child can exist, no problem
for me to understand this, the problem for me is:

when i choose updateinsertoption,ONLY parentdatarow is inserted,
childdatarow never enter into database, so i check system generated code
for dataset and datasetrelated adapters and adaptermanager line by line,
finally, i found how adaptermanager.updateall work. it use every
datatable'select method to extract added,modified,or deleted rows
based on dataviewrowstate,and then it use associated adapter to
update the datatable,the same way for every other datatable.that is
great for nonrelated datatable, when it comes to related datatables
(at least for me),it fails,take the above scenario for example,
system use parentadapter to update insert successfully, system will
change childdatarow's rowstate from added into modified because
foreignkey constraint,so childtable's select method will never
find the newly inserted childdatarow(because its rowstate now
is modified instead of added),therefor childadapter will never
execute insertcommand.

am i missing something to make it work here? or how should i solve
this problem? i don't think adding code such as setadded into system
generated code is a good method
Abinash_Sahoo 6-Apr-14 18:05pm
if possible, please post the code instead of description.
Blicker Hoffman 6-Apr-14 20:27pm
here is the code on button click

private void button1_Click(object sender, EventArgs e)
OilEquipmentDataSet.industrialPotentialClientRow ClientR = ReadClientRowFromControl();//(a method reading value to newly added Row,no error here)
OilEquipmentDataSet.IndustrialProductRow ProR = ReadProductRowFromControl();//(a method reading value to newly added row,no error here)
if (_m == Manipulation.Add) //(this is to make sure user is in adding mode,not in Edit mode)
catch (Exception Ex)
MessageBox.Show("something wrong: " + Ex.Message );


in the mainform, there is a button to update all changes to the database, only code in that area is adaptermanager.updateall(dataset). please let me know if more needed

1 solution

Sorry I did not get a chance to create a sample project and test, but you can check this link if it solves your problem:

Inserting Rows in Relationship using a Strongly Typed DataSet[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900