本人用pardox设计了一个表 其中一个字段是 Date型.字段名为  s_Time  现在有一个Query的查询要查询时间在某一个范围内的数据. 如下:
Query->Close();
Query->SQL->Clear();
Query->SQL->Text = "select * from table where s_time >=" + s_TimeS->Date+ " and
                   S_time<=" + s_TimeE->Date;
Query->Open();其中 s_TimeS和s_TimeE为  TDateTimePicker;  程序执行出错  说,类型不匹配.请问这是什么原因?
在线等? 如何才能实现这个查询 ?注意: 不能转换为字符串处理 因为程序会给出错误

解决方案 »

  1.   

    //以下程序肯定可以
    DateSeparator ='/';
    Query->Close();
    Query->SQL->Clear();
    Query->SQL->Text ="select * from table where s_time >='" +FormatDateTime("MM/DD/YYYY",s_TimeS->Date)+ "' and S_time<='" + FormatDateTime("MM/DD/YYYY",s_TimeE->Date)+"'";
    Query->Open();
      

  2.   

    因为TDateTime类型是浮点数,不能直接放进字符串的。楼上的方法一般情况下没有问题,不过最好还是要注意数据库的日期格式的配置。另外你可以用参数传递试试看。(Delphi中可以,不知道BCB中有没有问题)
    Query->Close();
    Query->SQL->Clear();
    Query->SQL->Text = "select * from table where s_time >= :SDate and
                       S_time<= :EDate";
    Query->Paramters->CreateParameter("SDate", ftDate, pdInput, -1, s_TimeS->Date);
    Query->Paramters->CreateParameter("EDate", ftDate, pdInput, -1, s_TimeE->Date);
    Query->Open();
      

  3.   

    "select * from table where s_time >=" + s_TimeS->Date+ " and
                       S_time<=" + s_TimeE->Date;
    c++里面有QuotedStr(s_Time)么?SQL语句为何不这样写:
    Select * from table where sTime between Time1 and Time2
      

  4.   

    查询日期格式的数据要加双引号的""
    'select * from table where s_time >="' + s_TimeS->Date+ '" and
     S_time<="' + s_TimeE->Date+'"';