日期:2014-05-18  浏览次数:20856 次

已在此范围定义了名为“scd”的局部变量
string CardID = this.TextBox1.Text.ToString();
  string FW_name = this.TextBox3.Text.ToString();
  string FW_price = this.TextBox4.Text.ToString();
  string number = this.TextBox5.Text.ToString();
  string tot_price = this.TextBox6.Text.ToString();
  //string tot_price = this.Lable5.Text.ToString();
  string zhekou = this.TextBox2.Text.ToString();
  string money = this.TextBox7.Text.ToString();
  int et = IsNumeric(money);
  if (et == -1)
  {
  Response.Write("<script>alert('充值必须为数字!')</script>");
  return;
  }
  SqlConnection con = new SqlConnection("Server=127.0.0.1;Database=HY;uid=HF;pwd=123456");
  con.Open();
  string temp = "insert into XFJL (CardID,FW_name,FW_price,number,zhekou)values('" + CardID + "','" + FW_name + "','" + FW_price + "','" + number + "','" + zhekou + "')";
  SqlCommand scd = new SqlCommand("insert into XFJL (CardID,FW_name,FW_price,number,zhekou)values('" + CardID + "','" + FW_name + "','" + FW_price + "','" + number + "','" + zhekou + "')", con);
SqlCommand scd = new SqlCommand("update HYXXB SET money= money+'" + et + "' where CardID = '" + CardID + "'", con); try
  {
  scd.ExecuteNonQuery();
  }
  catch (Exception ex)
  {
  Response.Write("<script>alert('结账失败');window.location.href='';</script>");
  }

  con.Close();
  Response.Write("<script>alert('结账成功');window.location.href='';</script>");



  }
 public int IsNumeric(string str)
  {
  int i;
  if (str != null && System.Text.RegularExpressions.Regex.IsMatch(str, @"^-?\d+$"))
  i = int.Parse(str);
  else
  i = -1;
  return i;
  }


我想进行2次数据库操作,该怎么改,我是新手,请指点下

------解决方案--------------------
SqlCommand scd = new SqlCommand("insert into XFJL (CardID,FW_name,FW_price,number,zhekou)values('" + CardID + "','" + FW_name + "','" + FW_price + "','" + number + "','" + zhekou + "')", con);
//执行
scd = new SqlCommand("update HYXXB SET money= money+'" + et + "' where CardID = '" + CardID + "'", con);
//执行