vendredi 23 janvier 2015

RollBack insert to multiple tables in SQL Server 2005

I want to use Transaction and rollback first time but I am confused as if how to in my case?


I want to insert records in multiple tables and I need to use for loop to insert more than one record in one table. And also I want to delete all records from all tables if some error occurred.


Let's take 3 tables as an example:



Insert into table1 values (a, b, c);

for(int i = 0; i < gridview1.rows.count; i++)
{
Insert into table 2 values (i, b, c);
}

Insert into table 3 values (a, b, c);


So this is just a short example of what I want. I tried few tutorials but those seems to be for different cases and pretty easy.


I have to use SQL Server 2005 and cannot go to 2008 or above..


Thanks in advance


Edit


Currently I am doing this using multiple stored procedure (one for each table) And I want to implement a transaction in it. Using Asp.net if possible will also be ok for me.


Aucun commentaire:

Enregistrer un commentaire