cyl_jay 发布留言 2008-6-9 15:25
数据绑定问题求助!!
用ComboBox绑定了数据库
我想用一个按钮来删除所选中的ComboBox项
sql语句:"delete from userinfo where username=" +ComboBox1.SelectedText;
可以运行
但是不能成功执行命令,请高手看看
cyl_jay 发布留言 2008-6-10 14:47
SQL语句有错误吗
f80051235 发布留言 2008-6-10 15:09
"delete from userinfo where username='" +ComboBox1.SelectedText+"'"
应该是少了两个单引号
cyl_jay 发布留言 2008-6-11 01:10
我改了,还是不行
我用sql2000的事件探查器来追踪,显示:
delete from userinfo where username=' '
如果改用usernamecb.SelectedItem,再用探查器追踪,显示:
delete from userinfo where username='System.Data.DataRowView'
'System.Data.DataRowView' 这不知道是什么意思
hebingbing 发布留言 2008-6-11 10:31
[un]cyl_jay[/un] 在 2008-6-11 01:10 AM 的发言:[/bo]
我改了,还是不行 我用sql2000的事件探查器来追踪,显示: delete from userinfo where username=' ' [/quote] 这个说明当执行这段代码的时候,ComboBox1根本就没有选择值。你先注释掉你的那段代码,然后在事件中让他输出ComboBox1的选择项,看能不能得到值,什么时候能出来值了,并且和你选择的项是一致的了,你的问题就解决了……cyl_jay 发布留言 2008-6-11 11:17 回复 5# hebingbing 的帖子可以了 用delete from userinfo where username='" +ComboBox1.SelectedValue+"'" 就可以,我绑定了ValueMember属性 但是不知道为什么 ComboBox1.SelectedItem和ComboBox1.SelectedText不行zhangwc 发布留言 2008-6-11 13:57 .Textqq82616454 发布留言 2008-6-13 23:12 delete from userinfo where username=" +ComboBox1.SelectedItem.tostring();这样呢?cyl_jay 发布留言 2008-6-15 23:07 [quote][un]qq82616454[/un] 在 2008-6-13 23:12 的发言:[/bo]
delete from userinfo where username=" +ComboBox1.SelectedItem.tostring();这样呢? |
我先前试过的,不行。不知道是什么原因,按道理讲,ComboBox1控件里显示的是数据表 中的username列的个项数据,但是用ComboBox1.SelectedItem.tostring
();就不能执行sql语句
cxcninde 发布留言 2008-6-19 09:48
ComboBox1.SelectedItem.Text
或者
ComboBox1.SelectedItem.Value
看你怎么设
页: [1]