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