Transaction in Ado.Net

Transaction is the collection of Commands. Transaction work on nothing or All function.

Means if a command fails then all command fails .

Steps to Put Transaction in
Setp1 : create the sqlTransaction object
Step 2: Define the Connection property. And set the BeginTransaction() function with Connection object.
Step3: write the Sql Commands
Step4: pass transaction object in command()
Step5: commit()/Rollback Transaction
For Example

//create your connection property first
SqlTransaction st;
SqlCommand cmd;
st = con.BeginTransaction();
cmd = new SqlCommand("Insert into A (id,Fname) values (1,'aashish')", con,st);
cmd = new SqlCommand("Insert into B (id1,Lname) values (1,'aashish')", con,st);

This entry was posted in Asp.Net, Sql. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s