cmd.CommandText = "update student set shuxue='" + textBox3.Text + "' where xuehao in(select xuehao from chengji where xuehao like '%" + textBox1.Text + "'%')";
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 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+"%");
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]);
建議可以用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 );
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=@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的值如果输入abc',那么就会有错撒....
不然引号搞晕你啊
sql = string.Format(sql , [0], [1]);
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
);