首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

已在此范围定义了名为“scd”的局部变量解决方法

2012-06-15 
已在此范围定义了名为“scd”的局部变量string CardID this.TextBox1.Text.ToString()string FW_name t

已在此范围定义了名为“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);
//执行

热点排行