困扰了挺久,求助。不知道哪儿出现问题了。c#连接excel,sheet名为table。
sql语句如下,
sql = "select * from [table$A:G] where ‘性别’ in (" + state + ")";
sql = sql + "and ‘名字’ in (" + tbxName.Text.ToString() + ")";
sql = sql + " and ‘年龄’ > " + tbxYearMin.Text.ToString() + " and ‘年龄’ < " + tbxYearMax.Text.ToString();
sql = sql+ " and ‘身高’ > "+ tbxHighMin.Text.ToString() + " and ‘身高’ < " + tbxHighMax.Text.ToString();
获得dataset语句:
ds = DataSetRead(sql, "table");
public static DataSet DataSetRead(string sql, string sheetName)
        {
            using (OleDbConnection OleConn = new OleDbConnection(OleConnectionString))
            {
                DataSet ds = new DataSet();
                OleConn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter(sql, OleConnectionString);
                da.Fill(ds, sheetName);
                return ds;
            }        }
da.Fill(ds, sheetName)有错误:至少一个参数没有被指定值。谢谢大家!

解决方案 »

  1.   

    你debug一下,把拼接后的sql语句贴出来看看。
      

  2.   


    行2:sql = sql + "and ‘名字’ in (" + tbxName.Text.ToString() + ")";and前少了个空格???     sql = sql + " and ‘名字’ in (" + tbxName.Text.ToString() + ")";
      

  3.   

    sql语句错误是汉字旁边的单引号整成全角的了,现在sql语句没有错误了:
    select * from [table$A:G] where '性别' in ('F','M') and '名字' in ('Dav','Chery')  and '年龄' > '20' and '年龄' < '100' and '身高' > '1.6' and '身高' < '2.0';
    但是EXCEL表里这几列不管我换成什么单元格格式:数值或文本或常规,都查询不出结果。即使是简单的select * from [table$A:G] where '性别' in ('F','M');也不可以。是什么原因呢,多谢指教!