我原来是用SQL2005的,现在用ACCESS ,在SQL里功能是正常的,问题应该就是出在时间上,我是用TEXTBOX提交时间的,ACCESS表里的时间格式是 日期/时间
  private void button1_Click(object sender, EventArgs e)
        {
            show();
        }
        private void show()
        {
            string strPath = "\\\\192.168.1.12\\共享文件\\求职名册" + "\\AAA.mdb";
            string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'";
            OleDbConnection oleCon = new OleDbConnection(ConStr);
            StringBuilder strSQL = new StringBuilder();
            oleCon.Open();
            DataTable dt = new DataTable("卡");
            OleDbDataAdapter da = new OleDbDataAdapter(getsql(),oleCon);
            da.Fill(dt);
            dataGridView1.DataSource = dt.DefaultView;
            oleCon.Close();        }
        private string getsql()
        {            string sql = "select * from 卡 where id>=0";            if (textBox4.Text != null && textBox4.Text != "" && textBox5.Text != null && textBox5.Text != "")
                sql += " and indate between '" + DateTime.Parse(textBox4.Text) + "' and '" + DateTime.Parse(textBox5.Text) + "'";//应该就是这里有问题,我不知道ACCESS的时间转换是否正确
            if (comboBox2.Text != null && comboBox2.Text != "")                sql += " and 卡状态='" + comboBox2.Text + "'";            return sql += "order by id desc";
        }
大家帮帮我吧!

解决方案 »

  1.   

    DateTime.Parse(textBox4.Text) 
    换成
    Convert.ToDateTime(textBox4.Text);
    试试!
      

  2.   

    1,打印出 sql 看是否合法
    2,
      

  3.   

    文本框的格式应该怎么输呢? 2008-6-1 不对吗?
    SQL 不会有问题的,我在SQL2005里是对的呀
      

  4.   

    access 里面不支持这种时间类型,你把时间转换了就可以了比如ToString("yyyy-MM-dd hh:ss:mm"),如果后面有毫秒的话access就保存不了了,呵呵~~~~~~~~~~~~~~
      

  5.   

    sql += " and indate between #" + DateTime.Parse(textBox4.Text) + "# and #" + DateTime.Parse(textBox5.Text) + "#"
      

  6.   

    sql += " and indate between #" + DateTime.Parse(textBox4.Text) + "# and #" + DateTime.Parse(textBox5.Text) + "#";
      

  7.   

    我这里试了一下,给你一样的,时间不会出问题
    会不会是卡状态出的问题,建议你调试获取一下你的SQL语句看看
      

  8.   

    是要加#号,我这里只试了一下Update语句,不好意思