delphi - Fast Report displaying incorrect data from ADOQuery -
i have problem fast report displaying incorrect data adoquery. use following sql.text
select * job_data inner join customer on job_data.cust_code = customer.cust_code job_data.ship_date between [date1] , [date2] order ship_date
fast report shows data ship_date = null.
if throw tdbgrid , attach data source attached same adoquery, dbgrid shows correct information.
i'm out of ideas, suggestions?
to answer questions dates come from:
var date1:string; date2:string; sql_str:string; begin date1:=inputbox('date range','enter beginning date',''); try strtodate(date1); except on econverterror begin messagedlg('please enter valid date. format xx/xx/xx', mterror, [mbok], 0); //showmessage('please enter valid date. format `enter code here`xx/xx/xx'); exit; end; end; date2:=inputbox('date range','enter ending date',''); try strtodate(date2); except on econverterror begin messagedlg('please enter valid date. format xx/xx/xx', mterror, [mbok], 0); //showmessage('please enter valid date. format `enter code here`xx/xx/xx'); exit; end; end; sql_str:= 'select * job_data inner join customer on ' + 'job_data.cust_code = customer.cust_code ' + 'where job_data.ship_date between '; sql_str:= sql_str+ ''' '; sql_st:=sql_str + date1; sql_str:= sql_str+ ''''; sql_str:= sql_str+ ' , '; sql_str:= sql_str+ ''' '; sql_str:= sql_str+ date2; sql_str:= sql_str+ ' '''; adoquery5 begin close; sql.clear; sql.text:= sql_str; open; end; frxreport2.showreport(); end;
the adoquery attached frxdbdataset2 attached frxreport2. doing nothing alter results in query.
no, have no code in report, generated wizard.
fastreport cannot display records ship_date
null
, because query shouldn't returning them based on where
clause if date1
, date2
assigned. means either dataset , fastreport aren't connected or in code assigning date values between
clause wrong, , dates aren't being provided query correctly.
the first place start looking make sure of report columns correctly assigned proper tfrxdataset
, proper database column. (click on report item (text object or whatever might be), , check dataset
, datafield
properties ensure correct.)
if that's not problem, may way you're building query, isn't correctly formatting dates ado. (you're using whatever format happens pass strtodate
calls without raising exception.)
the way you're setting sql unadviseable. it's unreadable , unmaintainable when try manage quoting in code.
you should use parameters, first , foremost protects against sql injection, allows database driver format quoted values , dates , keeps things readable. (you can use readable names parameters, when see them 6 months you'll know mean.)
var // other variable declarations here startdate, enddate: tdatetime; begin date1 := inputbox(whatever); try startdate := strtodate(date1); except // handle econverterror end; date2 := inputbox(whatever); try enddate := strtodate(date2); except // handle econverterror end; sql_str := 'select * job_data j'#13 + 'inner join customer c'#13 + 'on j.cust_code = c.cust_code'#13 + 'where j.ship_date between :startdate , :enddate'; adoquery5 begin close; // no need clear. if you're using same query more once, // move sql assignment , parameter.datatype somewhere // else, , don't set them here. // query can reused closing, changing parameter values, // , reopening. sql.text := sql_str; parameters.parambyname('startdate') begin datatype := ftdate; value := startdate; end; parameters.parambyname('enddate') begin datatype := ftdate; value := enddate; end; open; end; frxreport2.showreport; end;
Comments
Post a Comment