cmd.CommandText = "update student set shuxue="'+textBox3.Text'"where xuehao in(select Id from chengji where xuehao like'"+"%"+textBox1.Text+"%"+"')";

解决方案 »

  1.   

    cmd.CommandText = "update student set shuxue='" + textBox3.Text + "' where xuehao in(select xuehao from chengji where xuehao like '%" + textBox1.Text + "'%')";
      

  2.   

     where xuehao like '%" + textBox1.Text + "%')";多打了一个单引号
      

  3.   


    cmd.CommandText = "update student set shuxue='"+textBox3.Text+"'  where xuehao in(select Id from chengji where xuehao like '%"+textBox1.Text+"%')";
      

  4.   

    纯粹考视力cmd.CommandText = "update student set shuxue='"+textBox3.Text+"'  where xuehao in(select Id from chengji where xuehao like '%"+textBox1.Text+"%')";
      

  5.   

    cmd.CommandText = @"update student set shuxue='"+textBox3.Text+@"' where xuehao in (select Id from chengji where xuehao like '%"+textBox1.Text+@"%')";
      

  6.   

    cmd.CommandText = "update student set shuxue='" + textBox3.Text + "' where xuehao in(select xuehao from chengji where xuehao like '%" + textBox1.Text + "%')";
    //这样就对了、建议你用参数化的方法、避免字符串写错、如下:
    cmd.CommandText = "update student set shuxue=@aa where xuehao in(select xuehao from chengji where xuehao like @bb)";
    cmd.Parameters.AddWithValue("@aa",textBox3.Text );
    cmd.Parameters.AddWithValue("@bb","%"+textBox1.Text+"%");
      

  7.   

    你这样直接用TextBox.Text值会出错的,要进行必要的一些转换。
    如TextBox.Text的值如果输入abc',那么就会有错撒....
      

  8.   

    建议用string.format方法格式化你那个sql语句
    不然引号搞晕你啊
      

  9.   

    cmd.CommandText = "update student set shuxue="'+textBox3.Text'"where xuehao in(select Id from chengji where xuehao like'"+"%"+textBox1.Text+"%"+"')";写的好乱。C# 的特殊写法吗??cmd.CommandText = "update student set shuxue='"+textBox3.Text+"'where xuehao in(select Id from chengji where xuehao like'%"+textBox1.Text+"%')";
      

  10.   

    下次要写的话 还是使用 format 吧..string sql = "update student set shuxue='{0}' where xuehao in(select Id from chengji where xuehao like'%{1}%')";//获取公共类保存的用户登录信息.
    sql = string.Format(sql , [0], [1]);
      

  11.   

    建议先把sql语句输出来,如用label1.Text="...";或加断点,将输出的sql 语句放在查询分析器中调式,比较容易找到问题所在
      

  12.   

    建議可以用string.Format
    string sql = string.Format("UPDATE {0} SET {1}={2} WHERE xuehao in(select Id from chengji where xuehao like'{3}'",
                                    "student",
                                    "shuxue",
                                    textBox3.Text,
                                    textBox1.Text
                                 );