首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请大伙帮小弟我看上这句代码啊

2012-08-13 
请大伙帮我看下这句代码啊!!!cmd.CommandText update student set shuxue+textBox3.Textwhere xue

请大伙帮我看下这句代码啊!!!
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 + "'%')";

[解决办法]
where xuehao like '%" + textBox1.Text + "%')";

多打了一个单引号
[解决办法]

C# code
cmd.CommandText = "update student set shuxue='"+textBox3.Text+"'  where xuehao in(select Id from chengji where xuehao like '%"+textBox1.Text+"%')";
[解决办法]
纯粹考视力

SQL code
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+@"%')";
[解决办法]
C# code
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",


"shuxue",
textBox3.Text,
textBox1.Text
);
[解决办法]
建議用 string.format

热点排行