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

select 的有关问题

2012-02-06 
select 的问题有一张表table,其中一列名为水果,内容有苹果.香蕉.桔子等select*fromtablewhere水果等号后

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+ ' ' '
这样条件就是选定的文本内容了。

热点排行