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

问个比较菜的数据查询问题,谢谢请帮帮忙
string   sleListbox= "城市,单位。。。。。 ";//这一变量是动态的增加的
string   xlsPath   =   "C:\\Documents   and   Settings\\new\\桌面\\2007.xls ";   //   绝对物理路径
              string   connStr   =   "Provider=Microsoft.Jet.OLEDB.4.0; "   +
                                                                "Extended   Properties=Excel   8.0; "   +
                                                                "data   source= "   +   xlsPath;
                             
                           
//   查询语句
//我现在就是这一句有错误,我想问怎样把sleListbox这一变量作为查询所得的项,加入SQL语句中
                                string   sql   =   "SELECT   "+ "\ " "+sleListbox+ "\ " "+ "   FROM   [Sheet1$]   WHERE   价格=2.1   AND   月份   BETWEEN   200601   AND   200602 ";
                                ////string   sql   =   "SELECT   DISTINCT   城市   FROM   [Sheet1$]   WHERE   城市= "   +   " ' "   +   "佛山市 "   +   " ' ";

                                DataSet   ds   =   new   DataSet();

                                OleDbDataAdapter   da   =   new   OleDbDataAdapter(sql,   connStr);
                                da.Fill(ds);         //   填充DataSet                

                                //在这里对DataSet中的数据进行操作        


                                //输出,绑定数据
                                dataGridView1.DataSource   =   ds.Tables[0];
                                ////dataGridView1.DataBind();

------解决方案--------------------
问题就在这了,我上面的sql语句没有发生问题,但是取出来的数据就有问题了,比方说
我用“select 城市 from [Sheet1$] WHERE 价格=2.1 AND 月份 BETWEEN 200601 AND 200602 ";”
查出来是

城市
长沙
北京
...
================================================================================

string sql = "SELECT "+ "\ " "+sleLis