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

string sign = Convert.ToString(scd.ExecuteScalar());出现异常!

2012-04-13 
stringsign Convert.ToString(scd.ExecuteScalar())出现错误!!代码如下:protected void GridView1_Sele

string sign = Convert.ToString(scd.ExecuteScalar());出现错误!!
代码如下:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {

  string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["SmallHouseConn"]);
  SqlConnection conn = new SqlConnection(setting);
  conn.Open();
   
  string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
  string sqlstr = "select sign from homerepair where ID=" + id + "";
  SqlCommand scd = new SqlCommand(sqlstr, conn);
  string sign = Convert.ToString(scd.ExecuteScalar());//这段出错
  if (sign =="0")
  {
  sign ="1";
  }
  else

  {
  sign = "0";
   
  }
  scd.CommandText = "update homerepair set sign=" + sign + " where id=" + id ;
  scd.ExecuteNonQuery();
  this.bind();
  conn.Close();
   
  }
  数据库中的类型是:varchar()。
  vs中错误提示是语法错误

[解决办法]
sql语句
string sqlstr = "select sign from homerepair where ID='" + id + "'";

热点排行