C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Tips » Visual Studio »

Transaction in ADO.Net


Posted Date: 27 Oct 2009    Resource Type: Tips    Category: Visual Studio
Author: Ahmed Ali KhanMember Level: Bronze    
Rating: 1 out of 5Points: 3



The Code Snippet Demonstrates How Simple Transaction Works.




// Connection to your database using SQLConnection Object,Lets say SQLConnection Object name is sqlcon

SQLCommand sqlCom = sqlcon.CreateCommand();
SQLTransaction sqlTran;

// Start a local transaction

sqlTran = salcon.BeginTransaction();

/* Assign Both transaction object and connection to Command Object for pending local transaction */

sqlCom.Connection = sqlCon;
sqlCom.Transaction = sqlTran;

try
{
sqlCom.CommandText = "Insert or Update or Delete Command as per sql Syntax";
sqlCom.ExecuteNonQuery();

// Trying to Commit the Transaction

sqlTran.Commit();
MessageBox.Show("Records Are Written To Database....");

}
catch(Exception objException1)
{

MessageBox.Show("Commit Exception Occured :" + objException1.GetType());

// Trying to Rollback the Transaction

try
{
sqlTran.RollBack();
}
catch(Exception objException2)
{
MessageBox.Show("RollBack Exception Occured :" + objException2.GetType());
}


}






Responses

Author: Rabiya    04 Nov 2009Member Level: Gold   Points : 0
Good Info..
Keep Posting.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Transaction in ADO.Net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to make window.event in javascript in Firefox
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use