C #. NET Transaction mechanism example,

Source: Internet
Author: User

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 ();}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.