The transaction is atomic, either not executed, or fully executed, once a permanent save is successfully executed . and these are due to the atomicity of the transaction and the persistence of the database. . The following is a batch operation that unifies data modifications in a database , Leverage to Transactions .
TODO: Bulk modifying 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> return results of execution </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 be executed 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) {//Execution 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 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 rows of SQL statements in conjunction with several common SQL objects.