views:

25

answers:

1

I'm using vb.net 2008. And I am using ADO Update to Insert new data. So I have a Dataset with two tables - one a Parent and one a Child. When adding new Parent plus some child data on the client side, and then Inserting it into the DB (using TableAdapter.Update), how does the child get the new Parent ID?

A: 

If you are using SQL Server you will want to look into using one of the following:

  • Scope_Identity
  • @@IDENTITY
  • IDENT_CURRENT

In addition to this I think your best bet is to have a stored procedure that accepts parent and child information. Once you have inserted the parent Item you can get it's Identity and use it when inserting the child records.

Another option would be to break these into two separate inserts, one for the parent that returns the parents Identity and one for the children that use that Identity.

Abe Miessler