当前位置: 代码迷 >> ASP.NET >> select 的有关问题
  详细解决方案

select 的有关问题

热度:5375   发布时间:2013-02-26 00:00:00.0
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+ ' ' '
这样条件就是选定的文本内容了。
  相关解决方案