Hi, I have a problem i have a form which adding data to three tables, repair,custtomer and machine.first its add customer details and getting newly genrerated customer id from data base and use that customer id to add machine details and get newly generated machine id and finally add repair detail using customer id and machine id. if want that if its add details to one table it adds to all table and if cancel to add in one table then its cancel for all forms.
Thanks
always gullPosted Apr 1, 2009, 2:09 PM
Thanks for reply, I am using the same technique except i don't know how to put them in a single transaction.
Thanks once again
aru vPosted Apr 1, 2009, 5:12 AM
Hi,
In sql we can use "@@Identity" to get the identity column value when inserting record in to a table.
Use three sql variables to store the auto identity column values of the three tables.
When inserting into customer table,after insert statement set the auto identity column value to one of the variable,
Use the variable to insert values to Machine table.
same case with Repair table.
put the three insert statements in a single transaction.
Sample:
Insert into Customer
Set @custId = @@Identity
Insert into Machine details (using @custId)
Set @machineId = @@Identity
Insert into Repair details(using @custID,@machineId)
Regards,
Aru