日期:2014-05-18 浏览次数:20890 次
cmd.CommandText = "update student set shuxue='"+textBox3.Text+"' where xuehao in(select Id from chengji where xuehao like '%"+textBox1.Text+"%')";
------解决方案--------------------
纯粹考视力
cmd.CommandText = "update student set shuxue='"+textBox3.Text+"' where xuehao in(select Id from chengji where xuehao like '%"+textBox1.Text+"%')";
------解决方案--------------------
直接给你改成对的你下次遇到还是不明白,其实就是用加号连接字符串。你可以打个断点看一下你拼完的这个字符串是不是你想要的语句,就知道怎么改了。
------解决方案--------------------
cmd.CommandText = @"update student set shuxue='"+textBox3.Text+@"' where xuehao in (select Id from chengji where xuehao like '%"+textBox1.Text+@"%')";
------解决方案--------------------
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+"%");
------解决方案--------------------
你这样直接用TextBox.Text值会出错的,要进行必要的一些转换。
如TextBox.Text的值如果输入abc',那么就会有错撒....
------解决方案--------------------
建议用string.format方法格式化你那个sql语句
不然引号搞晕你啊
------解决方案--------------------
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+"%')";
------解决方案--------------------
下次要写的话 还是使用 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]);
------解决方案--------------------
建议先把sql语句输出来,如用label1.Text="...";或加断点,将输出的sql 语句放在查询分析器中调式,比较容易找到问题所在
------解决方案--------------------
建議可以用string.Format
string sql = string.Format("UPDATE {0} SET {1}={2} WHERE xuehao in(select Id from chengji where xuehao like'{3}'",
"student",