The transaction is atomic, either not running, or fully running, once it is successfully run and permanently saved . and this is precisely because of the atomicity of the transaction and the persistence of the database. . The following is a batch operation that unifies data churn in a database , Leverage to Transactions .
TODO: Batch churn data in a database CODE:
#region Extensionmethod///<summary>///Chen Fanglin-March 22, 2014 15:17:59//</summar, according to the number of students assigned y>//<param name= "Strstudentnoscore" > SQL statement for Add-on </param>//<returns> Returns the result of the run </retu Rns> public bool Teagivescores (string[] strstudentnoscore) {//Open database connection Sqlcon. Open (); Declares the SQL transaction sqltransaction Mytrans; SQL Command object SqlCommand mycmd = new SqlCommand (); Declares the connection database myCMD of the Command object. Connection = Sqlcon; Turn on transaction Mytrans = Sqlcon. BeginTransaction (); Sets the transaction mycmd that will run in the Command object. Transaction = Mytrans; try {//Traversal SQL statement in string array for (int i = 0; i < strstudentnoscore.length; i++) {mycmd.commandtext = Strstudentnoscore[i]; int R =mycmd. ExecuteNonQuery (); } Transaction submission Mytrans.commit (); return true; } catch (Exception) {//Run error, transaction rollback if (Mytrans! = null) Mytrans.rollback (); return false; } finally {//close connection if (Sqlcon! = null) Sqlcon. Close (); }} #endregion Extensionmethod
Summary
The transaction operation is approximate (temperature)
BeginTrans: Start a transaction
CommitTrans: Commit Transaction
RollbackTrans: Rolling back a transaction
It is primarily a good package for data processing, as a unit of processing. Work with multiple lines of SQL statements in conjunction with several objects that SQL uses frequently.
Transaction application-run multiple SQL statements