Seledt * from MyTable Where Format([领取时间],\"yyyy-mm-dd\") between  @StartDate and @EndDate ??Access这种格式化我没用过,不过你这样格式化的话肯定会将时分秒之类的截掉了,可以考虑这样写select xxx,yyy,...,Format([领取时间],\"yyyy-mm-dd\")
where 领取时间  between  @StartDate and @EndDate 你真的是使用Access吗?据我所知oledb使用参数只能用问号,而不能是@加名称???

解决方案 »

  1.   

    String ConString = " Seledt * from MyTable Where [领取时间] between  #"+StartDate+"# and #"+EndDate+#";试试看
      

  2.   

    这样我试过了,也不行,报错:日期/时间类型不正确access操作日期太麻烦了,我现在用字符串存储时间了,在access[领取时间]=为字符类型了,长度为 10,如:"2004-09-01",查找语句如下:
    String ConString = " Seledt * from MyTable Where [领取时间] between  @StartDate and  @EndDate;myCommand.Parameters["@StartDate"].Value = this.DateTimePicker1.Value.ToString("u").SubString(0,10);
    myCommand.Parameters["@EndDate"].Value = this.DateTimePicker2.Value.ToString("u").SubString(0,10);没有报错,但找出的记录不对,是不是字符串比较的问题???
      

  3.   

    关键是我要用参数化日期,
    这种参数:#@StartDate#
    会报错。
      

  4.   

    在ACCESS中比较时间要加#,如CompareDate > #年-月-日#
      

  5.   

    问题已经解决,不用参数了,直接写成
    String ConString = " Seledt * from MyTable Where [领取时间] between  dateTimePicker1.Value.ToString("u").Substring(0,10) and  dateTimePicker2.Value.ToString("u").Substring(0,10);
    就可以了,我想一定是参数的问题了, access就是支持不太好