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 + "'";