views:

443

answers:

1

Hi,

I have a page in which there are 3 sections.In the first section,i have some details to save in the Database.I am saving these details through a StoredProcedure(sql) named Procedure1.The details are stored in a table named Table1.There is a Primary key in the table named "ID".This "ID" is inserted automatically in the table.

In the second and third sections, i have Grids for Data Manipulation.The Details are inserted in tables Table2 and Table3 through StoredProcedures(sql),Procedure2,Procedure3 recpectively.

The "ID" which is generated automatically in Table1 needs to be inserted in Table2 and Table3.How can i do this?

The Details in Table1 should get Rollback when corresponding data is not inserted in Table2 and Table3,ie. these 3 sections are to be inserted simultaneously.

Now I have created a StoredProcedure in which i have combined all the 3 procedures.

Now how can i write code to Rollback the details? Or can anyone suggest another method to solve this?

+1  A: 

Just use a transaction, and call Transaction.Rollback() on error. It's the database's job to handle the details.

Jon Skeet
can i use another method for this?
Nandini
Why would you want to use another method? This is what databases are good at, and the code to take advantage of it is straightforward.
Chris Farmer
@Vineetha: You'd need a really good reason *not* to use database transactions here - in which case you should explain what that reason is. As Chris said, this is what databases are good at. Transactions are hard to implement - you really don't want to try to do them yourself.
Jon Skeet
No Jon,i just want to know if there is another method instead of using Transaction in vb.net other than sql.Anyway,Thank you,Jon and Chris
Nandini