0

i want to show report with date range
i have code

procedure TForm1.ButtonPreviewClick(Sender: TObject);
begin
    ...
    ADOQuery1.Active := False;
    ADOQuery1.SQL.Text:='';
    ADOQuery1.SQL.Text :='SELECT * FROM tablename WHERE datefield BETWEEN :startdate and :enddate';
    ADOQuery1.Parameters.ParamByName('startdate').DataType:= ftdate;
    ADOQuery1.Parameters.ParamByName('endate').DataType:= ftdate;
    ADOQuery1.Parameters.ParamByName('startdate').value:= datetostr(DateTimePicker1.Date);
    ADOQuery1.Parameters.ParamByName('enddate').value:= datetostr(DateTimePicker2.Date) ;
    ADOQuery1.Active := True;
    QuickRep1.Preview;
    ...
 end;

and i put 4 test records to tablename

number|date
1     |14/8/2015
2     |1/8/2015
3     |31/8/2015
4     |9/8/2015

if i click the button, quick report only showing first record, no matter what date i choose, like this

quickreport

number|date
1     |14/8/2015

with quick report properties
qrband title = qrlabel1 with caption 'quickreport'
qrband column header = qrlabel2 with caption 'number', qrlabel3 with caption'date'
qrband detail = qrdbtext1 & qrdbtext2 with dataset 'adoquery1', datafield 'numberfield' on qrdbtext1 and 'datefield' on qrdbtext2

how to show all data with date range filter?
thanks for your attention

  • If the column is of type DATE, and you're using `ftDate` as the parameter datatype, then why are you assigning `DateToStr` to the parameters? Use `ParamByName('enddate').Value := DatePicker1.Date` and let the database drivers do the proper formatting. (Also, post your **real** code in the future; the code you've posted uses `endate` when setting the parameter DataType, and `enddate` when setting the Value. One has a single *d*, the other has *dd*. If you want help with code that isn't working, provide the actual code with which you're having problems.) – Ken White Aug 14 '15 at 16:11
  • @KenWhite Solved, i use `Form1.ADOQuery14.SQL.add('select * from jurnal where [Tanggal Jurnal] >= #' + formatdatetime('mm/dd/yyyy',datetimepicker1.date) + '# and [Tanggal Jurnal] <= #' + formatdatetime('mm/dd/yyyy',datetimepicker2.date) + '#');` rather than code above, thanks for your attention sir. About the **real** code, i think that will respect other member with global language. And about endate & enddate i was typo there. Sorry for the trouble. – Banned User Aug 15 '15 at 17:25

0 Answers0