日期:2014-05-19  浏览次数:20602 次

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