读书人

select 的有关问题

发布时间: 2012-02-06 15:52:44 作者: rapoo

select 的问题
有一张表table,其中一列名为水果,内容有苹果.香蕉.桔子等
select * from table where 水果=
等号后为ListBox中选择的项的ListItem Text


[解决办法]
string str=ListBox1.SelectedItem.Text;

sqlStr= "select * from table where 水果= ' "+str+ " ' ";

另外,最好用参数做选择。例如,把SQL写成:
sqlStr= "select * from table where 水果=@fruite ";
然后,cmd.Parameters.AddWithValue( "@fruite ",str); //cmd为DbCommand对象
[解决办法]
select * from table where 水果= ' ' '+ListItem.SelectedItem.Text+ ' ' '
这样条件就是选定的文本内容了。

读书人网 >asp.net

热点推荐