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
childdatarow.SetParentRow(parentdatarow,relationconstraintnamestring)
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