Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Parameters in a TADOQuery

Status
Not open for further replies.

PaidtheUmpire

Programmer
Jan 4, 2004
105
AU
Can it be done...

I am using ADOTables and Connection etc. in Delphi 7.

Any ideas?
 
I will suggest dynamically defining the SQL property of the ADOQuery at run time, using this approach you could re-define the parameters ad hoc.

Opp.
 
with Query1 do
begin
Close;
SQL.clear;
SQL.Add('select blah from blah');
SQL.Add('where param = :param);
ParamByName('param').AsString := 'value1';
Open;
First;
while not eof do
begin
DoStuff;
Next;
end;
Close;
ParamByName('param').AsString := 'value2';
Open;
First;
while not eof do
begin
DoMoreStuff;
Next;
end;
end;

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
I use this quite successfully.
You'll need a tADOconnection, and a tADOquery.
Within the query, set the property of the SQL to something like this:
[tt]
SELECT * FROM [Image]
WHERE (pat_handle= :patient
AND int(acq_time)= :scandate AND ScanType= :sc_type)
[/tt]

The Parameters property in this query uses Patient (an OLE string) and ScanDate (ftLargeInt)

Then programatically you can change the parameters viz:
[tt]
procedure AdjustDateQuery(nScan : integer; sDate : string);
// redo the query on this patient with a specified scan date and type
begin
with ADOquery_image do begin
scandate := StrToDate(sDate); // convert date text to tDateTime (large integer)
close; // close the query to allow adjustment
Parameters.ParamByName('patient').value :=
ADOtable_Patients.FieldValues['pat_handle'];
Parameters.ParamByName('scandate').value :=
ScanDate; // assign date to parameter
Parameters.ParamByName('sc_type').Value :=
nScan; // get the right scan type
SQL.Text :=
'SELECT * FROM [Image] WHERE pat_handle= :patient AND int(acq_time)= :scandate AND ScanType= :sc_type)'; // be careful with the = : positions!
open; // re-open the query to apply it
end;
end;

[/tt]

Hope that helps

Cheers

Chris ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top