//被调用的类
public static bool add(string sql)
{
  bool a = true;
  string con =  "Data Source=.;Initial Catalog=money;Integrated Security=True";
  SqlConnection cnn = new SqlConnection();
  cnn.ConnectionString = con;
  cnn.Open();  SqlCommand com = new SqlCommand(sql,cnn);
  com.ExecuteNonQuery();
  return a;
}
 //直接执行操作
private void button7_Click(object sender, EventArgs e)
{
   string sql = "update liu set 标题='" + textBox3.Text + "',类别='" + comboBox3.Text + "',时间='" + d + "',内容='" + textBox5.Text + "' where 编号='" + aa + "'";  string con =  "Data Source=.;Initial Catalog=money;Integrated Security=True";
  SqlConnection cnn = new SqlConnection(con);
  cnn.Open();  SqlCommand com = new SqlCommand(sql,cnn);
  com.ExecuteNonQuery();
  cnn.Close();
}
错误提示: 第 1 行: '=' 附近有语法错误。

解决方案 »

  1.   

    string   sql   =   "update   liu   set   标题= ' "   +   textBox3.Text   +   " ',类别= ' "   +   comboBox3.Text   +   " ',时间= ' "   +   d   +   " ',内容= ' "   +   textBox5.Text   +   " '   where   编号= ' "   +   aa   +   " ' "; 
    这句有问题,改为:
    string  sql =  "update   liu   set   标题= ' "   +   textBox3.Text   +   " ',类别= ' "   +   comboBox3.Text   +   " ',时间= ' "   +   d   +   " ',内容= ' "   +   textBox5.Text   +   " '   where   编号' "   +   aa   +   "' "; 
      

  2.   

    string sql = "update liu set 标题= ' " + textBox3.Text + " ',类别= ' " + comboBox3.Text + " ',时间= ' " + d + " ',内容= ' " + textBox5.Text + " ' where 编号= ' " + aa + "' "; 
      

  3.   

    string str = "update tushu set 名称='"+b[1]+"',索书号='"+b[2]+"',存放位置='"+b[3]+"',出版社='"+b[4]+"',作者='"+b[5]+"',数量="+b[6]+",价格="+b[7]+",出版时间='"+b[8]+"',页数='"+b[9]+"',入库时间='"+b[10]+"',借出次数="+b[11]+",状态='"+b[12]+"',情况='"+b[13]+"',附件='"+b[14]+"'where 编号='"+aa+"'";请问这句查询语句有问题吗?
      

  4.   


    where 前加空格    这种错误你不确定就设断点取到str的值,在数据库执行这条语句看有没有问题