views:

382

answers:

2

I am using C#.Net application in which i created a dataset.Now i want to create a method in which i will enter a record in one table which will return a value ie primary key.Now by using that primary key i have to insert records in 5 tables and i have to use that primary key as a foreign key for this 5 tables using dataset.

A: 

Have you tried temporary key linkage until the DB generates the final key? Works great for me.

Joshua
A: 

You need to tell your parent table's table-adapter to refresh the data-table after update operation. This is how you can do that.

  1. Open the properties of ParentTableAdapter -> Default Select Query -> Advnaced options. and Check the option of Refresh the data table. Save the adapter now. Now when you call update on table-adapter, the data-table will be updated [refreshed] after the update operation and will reflect the latest values from database table. if the primary-key or any coloumn is set to auto-increment, the data-table will have those latest value post recent update.

  2. Now you can Call the update as ParentTableAdapterObj.Update(ds.dataTable);

  3. Read latest values from the ParentDataTable(ds.dataTable) coloumns and assign respective values into the child table before update. This will work exactly the way you want.

alt text

this. __curious_geek