1 private void bt_Save_Click(object sender, System.EventArgs e)
2 {
3 //创建更新字符串,在.NET开发中应该尽量采用DataSet方式更新
4 string sql1="update [distribute] set ";
5 sql1+="distributedate='"+TextBox4.Text.Trim()+"',";
6 sql1+="ip='"+TextBox5.Text.Trim()+"',";
7 sql1+="dispersonname='"+TextBox4.Text.Trim()+"' ";
8 sql1+="where 你的条件";
9
10 string sql2="update [pc] set ";
11 sql2+="pctype='"+TextBox8.Text.Trim()+"',";
12 sql2+="brand='"+TextBox9.Text.Trim()+"',";
13 sql2+="cpu='"+TextBox10.Text.Trim()+"',";
14 sql2+="memory='"+TextBox11.Text.Trim()+"',";
15 sql2+="harddisk='"+TextBox12.Text.Trim()+"',";
16 sql2+="mainboard='"+TextBox13.Text.Trim()+"',";
17 sql2+="optdisk='"+TextBox14.Text.Trim()+"',";
18 sql2+="display='"+TextBox15.Text.Trim()+"',";
19 //price 如果是数字型则不能用引号括起来
20 sql2+="price='"+TextBox16.Text.Trim()+"',";
21 sql2+="outdevice='"+TextBox17.Text.Trim()+"',";
22 sql2+="pc_remark='"+TextBox18.Text.Trim()+"' ";
23 sql2+="where 你的条件";
24
25
26 //创建数据对象
27 SqlConnection conn=new SqlConnection("你的连接字符串,最好写在配置文件中");
28 SqlCommand cmd1=new SqlCommand(sql1,conn);
29 SqlCommand cmd2=new SqlCommand(sql2,conn);
30
31 //定义一个事务来保持cmd1/cmd2同步更新
32 conn.Open();
33 SqlTransaction trans=conn.BeginTransaction();
34 cmd1.Transaction=trans;
35 cmd2.Transaction=trans;
36
37 try
38 {
39 cmd1.ExecuteNonQuery();
40 cmd2.ExecuteNonQuery();
41 //事务提交
42 trans.Commit();
43
44 Response.Redirect("XQKK.aspx");
45
46 }
47 catch(Exception E)
48 {
49 //事务回滚
50 trans.Rollback();
51 ErrorMsg.Text=E.Message;
52 }
53 finally
54 {
55 conn.Close();
56 }
57 }
58
59
2 {
3 //创建更新字符串,在.NET开发中应该尽量采用DataSet方式更新
4 string sql1="update [distribute] set ";
5 sql1+="distributedate='"+TextBox4.Text.Trim()+"',";
6 sql1+="ip='"+TextBox5.Text.Trim()+"',";
7 sql1+="dispersonname='"+TextBox4.Text.Trim()+"' ";
8 sql1+="where 你的条件";
9
10 string sql2="update [pc] set ";
11 sql2+="pctype='"+TextBox8.Text.Trim()+"',";
12 sql2+="brand='"+TextBox9.Text.Trim()+"',";
13 sql2+="cpu='"+TextBox10.Text.Trim()+"',";
14 sql2+="memory='"+TextBox11.Text.Trim()+"',";
15 sql2+="harddisk='"+TextBox12.Text.Trim()+"',";
16 sql2+="mainboard='"+TextBox13.Text.Trim()+"',";
17 sql2+="optdisk='"+TextBox14.Text.Trim()+"',";
18 sql2+="display='"+TextBox15.Text.Trim()+"',";
19 //price 如果是数字型则不能用引号括起来
20 sql2+="price='"+TextBox16.Text.Trim()+"',";
21 sql2+="outdevice='"+TextBox17.Text.Trim()+"',";
22 sql2+="pc_remark='"+TextBox18.Text.Trim()+"' ";
23 sql2+="where 你的条件";
24
25
26 //创建数据对象
27 SqlConnection conn=new SqlConnection("你的连接字符串,最好写在配置文件中");
28 SqlCommand cmd1=new SqlCommand(sql1,conn);
29 SqlCommand cmd2=new SqlCommand(sql2,conn);
30
31 //定义一个事务来保持cmd1/cmd2同步更新
32 conn.Open();
33 SqlTransaction trans=conn.BeginTransaction();
34 cmd1.Transaction=trans;
35 cmd2.Transaction=trans;
36
37 try
38 {
39 cmd1.ExecuteNonQuery();
40 cmd2.ExecuteNonQuery();
41 //事务提交
42 trans.Commit();
43
44 Response.Redirect("XQKK.aspx");
45
46 }
47 catch(Exception E)
48 {
49 //事务回滚
50 trans.Rollback();
51 ErrorMsg.Text=E.Message;
52 }
53 finally
54 {
55 conn.Close();
56 }
57 }
58
59