C #. NET Transaction mechanism example,
. NET Transaction mechanism
When it comes to the transaction mechanism, for example, when we import orders, Several SQL commands may be linked. However, if the middle part of the data has a problem one day, this will lead to insert half, in the future, inventory may be out of stock or order details may be faulty, so we will apply the transaction mechanism.
All SQL commands are executed only after the entire transaction mechanism is completed.
Public static MySqlConnection openMysqlConnection () {MySqlConnection conn = new MySqlConnection ("zookeeper"); conn. open (); return conn;} protected void Button1_Click (object sender, EventArgs e) {using (MySqlConnection con = new MySqlConnection () {MySqlConnection conn = openMysqlConnection (); mySqlTransaction tran = conn. beginTransaction (); // do something} tran. commit ();}