Click here to Skip to main content
14,869,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have seen some problem regarding to data relation. The master and child table are related by an integer column. This column is Identity column and it automatically increments its value when the update command of the DataAdapter is called. The problem occurs when I try to add a new row. The master table works normally. However the detail table is not related with the master table accordingly. For example, if the value of the relating column is the new master table row is 10 but that of the detail is -1 or -2 or -3 ...

I have tried to call the fill command on the the master table after any new insert; then create the detail table. However, Performance wise this is not recommendale.

Is there any way to work around this problem.
Posted

1 solution

One way to handle this is to use the OUTPUT clause in your insert statement. With output you can get the value of the identity column from the inserted row without making an extra call to the server.

More info: http://msdn.microsoft.com/en-us/library/ms177564.aspx[^]
   

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