我加入控件为:datetimepicker1/datetimepicker2  /edit1/edit2/ 这四个控件,我的表中有两个字段:   num , time   我需要在edit 中输入与num相符合的数字, 然后  对num 进行 count(num) ; 条件为:输入时间为time= datetimepicker 控件选择的值,  然后。用EDIT2 控件来显示 count 的结果。
 
  想请高人给一段完整代码。 

解决方案 »

  1.   

    无非就是几个条件组合在一起,先熟悉一下SQL语句吧,你给的条件也不明确,看看书自己写
      

  2.   

    Var ssql:string; I:integer;
       Qy,qy1:tadoquery;
    Begin
      Qy.close;
      Qy.sql.clear;
      Qy.sql.add(“select num from table order by num”);
      Qy.open;
    For I:=0 to qy.recordcount-1 do begin 
      If trim(edit1.text)=qy.fieldbyname(num).asstring then begin
    Qy1.close;
    Qy1.sql.clear;
    Qy1.sql.add(‘select count(num) as AA from table where time=formatdatetime(‘yyyy/mm/dd’, datetimepicker.datetime)’);
    Qy1.open;
    Edit2.text := qy1.fieldbyname(‘AA’).ASSTRING;
    End; 
    End;
    End;
      

  3.   


    adoQuery.close;
    adoQuery.sql.text:='select count(1) from table1 where num='+Trim(Edit1.text)
                      +' and time='''+datetimetostr(datetimepicker1.datetime)+'''';
    adoQuery.open;edit2.text:=adoQuery.fields[0].asstring;
      

  4.   

    支持楼上
    adoQuery.close;
    adoQuery.sql.text:='select count(1) from table1 where num='+Trim(Edit1.text)
                      +' and time='''+datetimetostr(datetimepicker1.datetime)+'''';
    adoQuery.open;edit2.text:=adoQuery.fields[0].asstring;