我的数据库是通过odbc连接到一个oracle数据库上的,带有密码 
数据库中包含有时间这个字段,例如“2003-03-23” 这样的数据, 还有编号这个字段。我加了两个控件datetimepicker,想通过时间来查询表中的记录,
比如:。  表单中我加入了query \ datesource\dbgird \ edit \ datetimepicker (2个) 这些控件,实现的目的是,在 edit中输入我要查找的编号,时间控件1上选取"2001-01-01" 在时间控件2上选取“2003--3-23” 然后回车,把这个时间段中的所有与编号相符合的记录全部显示出来(要求前面有一个序号)/表单中要有一个地方能显示这个记录总数,查询的时候,如何输入的内容不存在,需要有一个提示,我现在在时间控件的使用上出了问题/还有就是查询时,记录不存在的情况,没提示,//程序运行时,总是要提示输入密码,(能不能把密码在程序中设置,不在提示输入呢?)请指点。 

解决方案 »

  1.   

    在http://community.csdn.net/Expert/topic/4634/4634245.xml?temp=.2454035中不是解决了?
      

  2.   

    查询一段时间
    Query.sql.add('select * from table where datetime bwtween :begin and :end'');
    Query.aramByName('begin').Value :=FormatDateTime('yyyy-MM-dd',datetimepicker1.date);
    Query.ParamByName('end').Value :=FormatDateTime('yyyy-MM-dd',datetimepicker2.date);
    ;
      try
        open
    ....Query.recordcount就是查询总数if Query.recordcount<0 then
      ShowMessage('没有纪录');
    database的loginprompt设为false,将密码写入odbc,或者params属性里
    可以不用每次填登录密码你的操作系统中时间格式应设置为2006-03-23这种格式与数据库中的对应,或写个程序自己包括各种格式,否则数据库中不能找到
      

  3.   

    系统的时间格式和TimePicker的时间格式是不一样的.系统的是2006-03-23而TimePicker的是2006- 3-23
    注意这里面是空格
    所以要像楼上说的那样自己把格式转化一下
    最好写个转换的函数
      

  4.   

    我这样写的,请大家鉴定一下,
     
       str_d1:=formatdatetime('yyyy-mm-dd'),dtp_1.datetime);
       str_d2:=formatdatetime('yyyy-mm-dd'),dtp_2.datetime);
       录入日期between '''str_dl''' and '''str_d2'''
      

  5.   

    我全部的代码,你帮我看一下:
     var
        str1: string;
        str2: string;    begin
        str1:=Formatdatetime('yyyy-mm-dd',Datetimepicker1.DateTime);    str2:=Formatdatetime('yyyy-mm-dd',Datetimepicker2.DateTime);    if key =13
        then begin
        query1.Close;
        query1.SQL.Text:='select * from tablename where 编号 like ''%'+EDIT1.Text+'%''' and time between '''+str1+''' and '''+str2+''';
        query1.Open;
        end;
    我要的是在EDIT中输入一个编号,然后,在DBGIRD中显示,两个时间之间的所有关于这个编号的记录 
      

  6.   

    var
        str1: string;
        str2: string;    begin
        str1:=Formatdatetime('yyyy-mm-dd',Datetimepicker1.DateTime);
        str2:=Formatdatetime('yyyy-mm-dd',Datetimepicker2.DateTime);
        if key =13
        then begin
        query1.Close;
        query1.SQL.Text:='select * from tablename where 编号 like ''%'+EDIT1.Text+'%''' and time between '''+str1+''' and '''+str2+''''; //这里多加一个'
        showmessage(query1.sql.text);//这里看一下组合出来的SQL语句语法
        query1.Open;
        end;///////////////////////
    看执行结果是不是你想要的