delphi - Error when using parameter in ADOQuery -
i have simple code check if record exists in table, returns runtime error :
arguments of wrong type, out of acceptable range, or in conflict 1 another.
my code :
function tdatamodulemain.barcodeexists(barcode: string): boolean; begin if adoquerysql.active adoquerysql.close; adoquerysql.sql.clear; adoquerysql.sql.text := 'select count(1) card barcode = (:testbarcode)'; adoquerysql.parameters.parambyname('testbarcode').value := barcode; adoquerysql.open; // here runtime error appears result := adoquerysql.fields[0].asinteger = 1; adoquerysql.close; adoquerysql.parameters.clear; end;
the field barcode in table card of type nvarchar(100)
in debug see parameter created, , gets populated correct value.
running query in sql server management studio works.
i found how pass string parameters tadoquery? , checked code code in answer don't see problems here.
adoquery error using parameters did not me.
it no doubt simple have missed dont see now.
edit : things tried suggestions in comments:
.paramcheck := true (default) .parameters.parambyname('testbarcode').datatype := ftstring .parameters.parambyname('testbarcode').datatype := ftwidestring
none of these worked however.
what did using non-shared adoquery this, , 1 did job without errors. using solution still looking @ shared adoquery out of curiousity exact problem is.
edit: source of problem found.
i used function provided martina examine both dynamic created query , shared adoquery , found 1 difference.
shared adoquery had property filled :
executeoption := [eoexecutenorecords]
and dynamic created query not.
since property not set in designtime did not see it. after clearing property [] shared adoquery worked again.
going switch using non shared adoquery kind of work been suggested.
thanks assistance.
the following isn't intended complete answer q, follow comment "all have inspect form's dfm , compare properties of original adoquery unshared one. answer should lie in difference(s)" , reply unshared query created dynamically.
there no "voodoo" involved in difference in behaviour between 2 adoquerys. it's question of capturing differences are.
so, need, debug problem yourself, code compare properties of 2 components, if 1 or both of them created dynamically. using following routine on both components enable that:
function tform1.componenttostring(acomponent : tcomponent) : string; var ss : tstringstream; ms : tmemorystream; writer : twriter; begin // note: there may more direct way of doing following, without // needing intermediary tmemorystream, ms ss := tstringstream.create(''); ms := tmemorystream.create; writer := twriter.create(ms, 4096); try writer.root := self; writer.writesignature; writer.writecomponent(acomponent); writer.flushbuffer; ms.position := 0; objectbinarytotext(ms, ss); result := ss.datastring; writer.free; ms.free; ss.free; end; end;
over ...
Comments
Post a Comment