各位大虾:    我想用datetimepicker来查询一段日期的数据访问sqlserver中的一个表中的smalldatetime字段的数据;用的是ADO连接   语句如下:   var d1,d2,s1:string;
      d1:=datetimetostr(datetimepicker1.datetime)
      d2:=datetimetostr(datetimepicker2.datetime)
      s1:='select * from danju where danju.endtime>=d1 and danju.endtime<d2     但程式运行会说列名‘d1'无效,不知各位是如何把datetimepicker中的日期给到sql语句中的    多谢各位赐教!    

解决方案 »

  1.   

    老大,你也跟我一样啊,是菜鸟,你的sql语句都写错了啊
      

  2.   

    字符串不能这样比较大小的,如果d1,d2是日期格式的话,还要以
    你可以直接用datetimepicker1.datetime用为日期就可以了
    'select * from danju where endtime>=datetimepicker1.datetime and endtime<datetimepicker2.datetime
    没有验证,自己再看看吧
      

  3.   

    s1:='select * from danju where danju.endtime>='''+d1+''' and danju.endtime<'''+d2+''''或者s1:='select * from danju where danju.endtime>=:d1 and danju.endtime<:d2'
    adoquery1.sql.add(s1);
    adoquery1.Parameters.ParamByName('d1').Value:=d1
    adoquery1.Parameters.ParamByName('d2').Value:=d2
      

  4.   

    呵呵
      Sql:='Select * from 表 where  时间>'+D1+' and 时间<'+D2
      

  5.   

    s1:='select * from danju where danju.endtime>='''+d1+''' and danju.endtime<'''+d2+''''
      

  6.   

    with Querydo
       BEGIN
        Close ;
        ParamByName('name').ASSTRING := name.KeyValue ;
        ParamByName('S_DATE').AsDatetime := DateTimePicker3.DateTime ;
        ParamByName('E_DATE').AsDatetime := DateTimePicker4.DateTime ;    
        open ;
       end;
      

  7.   

    什么数据库?acess好象前后要加#号
      

  8.   

    Formats a TDateTime value.UnitSysUtilsCategorydatetime routinesDelphi syntax:function FormatDateTime(const Format: string; DateTime: TDateTime): string; overload;
    function FormatDateTime(const Format: string; DateTime: TDateTime; const FormatSettings: TFormatSettings): string; overload;C++ syntax:extern PACKAGE AnsiString __fastcall FormatDateTime(const AnsiString Format, System::TDateTime DateTime);
    extern PACKAGE AnsiString __fastcall FormatDateTime(const AnsiString Format, System::TDateTime DateTime, const TFormatSettings FormatSettings);DescriptionFormatDateTime formats the TDateTime value given by DateTime using the format given by Format. See Date-Time format strings for more information.If the string specified by the Format parameter is empty, the TDateTime value is formatted as if a 'c' format specifier had been given.The first form of FormatDateTime is not thread-safe, because it uses localization information contained in global variables. The second form of FormatDateTime, which is thread-safe, refers to localization information contained in the FormatSettings parameter. Before calling the thread-safe form of FormatDateTime, you must populate FormatSettings with localization information. To populate FormatSettings with a set of default locale values, call GetLocaleFormatSettings.
    FormatDateTime函数进行指定的日期和时间形式的格式化,一次来符合你的数据库日期和时间格式的特殊要求!formatdatetime('yyyy-mm-dd hh:mm:ss',datetimepicker1.datetime)
    这样就是一个例子阿!!