I wrote code like this :
sql1 :='select sum(jumlah) as debet from kasir_kas_transaksi where flag in (1,3) and tanggal = to_date('+quotedstr(after)+','+quotedstr('dd-mm-yyyy')+')';
with zquery1 do begin
close;
sql.clear;
sql.Add(sql1);
execSQL;
end;
edit1.Text:=zquery1.fieldbyname('debet').asstring;
then an error occured saying field 'debet' does not exist. is there something wrong in the code? I am using delphi 7 and zeos as connection, as well as oracle 11g as db. Thank you!
Use
Open
, notExecSQL
.ExecSQL
is for queries that don't return result sets (INSERT
,DELETE
, andUPDATE
).Open
is for queries that return rows. You also don't need to useSQL.Clear;
and thenSQL.Add();
- you can just setSQL.Text
directly instead.(You should stop using
with
; that's a different topic, but I left it here because it's your code and not mine.)And as a note, stop concatenating SQL and use parameters instead. String concatenation with user input leaves you wide-open for SQL injection. Google Little Bobby Tables to find out why that's a bad thing if you don't know already. You can find an example here of writing your code using parameters instead.