【winform】编程
ADO.net连接excel代码如下:public DataSet LoadDataFromExcel(string filePath)
        {
            try
            {
                string strConn;
                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=0;'";
                OleDbConnection OleConn = new OleDbConnection(strConn);
                OleConn.Open();
                OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
                DataSet OleDsExcle = new DataSet();
                OleDaExcel.Fill(OleDsExcle, "Sheet1");
                OleConn.Close();
                return OleDsExcle;
            }
            catch (Exception err)
            {
                MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return null;
            }
        }
在调用函数进行筛选时。sql查询语句为:select * from [表名$] where 日期 >= '2010-7-1' and 日期 <= '2010-7-11'但是发现筛选后的数据的日期列的日期居然是2010-7-1、2010-7-10和2010-7-11,琢磨了半天也不明白啊,高手指点一下吧。注:我Excel表的日期那个列设置成“文本格式”和“日期格式”都试过,均无效。

解决方案 »

  1.   

    你要把“日期 ”先转换为DATE格式的才能这样的
      

  2.   


    select * from [表名$] where CONVERT(datetime, 日期) >= '2010-7-1' 
    and CONVERT(datetime, 日期) <= '2010-7-11'
      

  3.   

    下面的是我刚测试成功的代码
    其中InTime的数据类型为nvarchar(100) 通过数据转换执行了查询
    表中数据:
    002 Alison 2010-01-01
    003 Sophie 2010-03-01
    asdf sadf 2010-05-01
    kevin sdf 2010-07-01
    SELECT * FROM tb_Student 
    WHERE  CONVERT(datetime,InTime)>'2010-01-01' 
    AND CONVERT(datetime,InTime)<'2010-07-01'
    执行后结果003 Sophie 2010-03-01
    asdf sadf 2010-05-01
      

  4.   


    convert这个函数我也想过了。但是报错,表达式中'convert'函数未定义.