Insert record to multiple tables which are dependent on each other in c# with Transaction -


I'm new to C #

I got two tables: Employee Table (E_ID (PK) , First_Name, Last_Name, Address, DOB, Email) Bank Database Table (ID (PK), Bank_Name, ACDO, E_ID (FK))

Both PK auto increments are.

The problem now is, I need to put both the tables together, but if the employee ID (e-ID) is generated during the increment, then I will put the details of the bank on that operation in E_id How do I get that value? There is a need to use the transaction here for database concentration. I

Can anyone explain in a very easy way? thank you in advanced.

The best way I'm thinking of getting it is to have a stored procedure. You can use to get the identification of previously added records and to make sure that both the inserted queries are executed or none.

  BEGIN transfer; Include the first employee (first_name, last_name, address, dob, email) values ​​(@funam, lam, etc.) - get the final identification value for entering the identification column SET @E_Id = SCOPE_IDENTITY in the same radius (); Finally catch the INSERT (bank_name, acc_no, E_id) VALUES (@bname, @ano, @E_id) in the bank account, if @@ transcount & gt; 0 rollback transactions; End catches; IF @@ TRANCOUNT & gt; 0 comtrate transactions;  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -