Skip to content

Adding into multiple table from one form

always gull

Asked Mar 31, 2009, 2:17 PM EDT2 answers
Share
LinkedInX

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

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    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

    0
  • 0

    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

    0