当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

.Net简单使用事务

  01 <SPAN style="FONT-FAMILY: verdana,geneva"><SPAN style="FONT-SIZE: small">                OleDbConnection Conn=new OleDbConnection(SQLHelper.ConnString().ToString());

  02                 Conn.Open();

  03                 OleDbTransaction Tran = Conn.BeginTransaction();

  04                 OleDbCommand Comm = new OleDbCommand();

  05                 Comm.Connection = Conn;

  06                 Comm.Transaction = Tran;

  07                 try

  08                 {

  09                     Comm.CommandText="update customers set c_money=C_money-'" +textBox2.Text.Trim() + "' where c_account='" + label2.Text + "' ";

  10                     Comm.ExecuteNonQuery();

  11                     Comm.CommandText = "update customers set c_money=C_money+'"+textBox2.Text.Trim()+"' where c_account='" +textBox3.Text.Trim() + "' ";

  12                     Comm.ExecuteNonQuery();

  13                     Tran.Commit();

  14                     MessageBox.Show("你已成功向账户["+textBox3.Text.Trim()+"]转账["+textBox2.Text.Trim()+"]元!");

  15                 }

  16                 catch (Exception)

  17                 {

  18                     Tran.Rollback();

  19                     MessageBox.Show("转账失败,请重新操作!");

  20                 }

  21                 finally {

  22

  23                     Conn.Close();

  24                 }

  25 </SPAN></SPAN>

  0 0 0

  (请您对文章做出评价)

相关内容
赞助商链接