Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2001, 11:03 AM
Excalibur Excalibur is offline
Junior Member
 
Join Date: Jan 2001
Posts: 16
Default Query Parameter Question...?

How can I create a parameter on a query at run time? Thanks a lot for your answer.
Reply With Quote
  #2  
Old 01-04-2001, 09:40 PM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default RE: Query Parameter Question...?

there are two ways

first in case you open the same querry multiple time in same form with different param values then you can create a global variable in form say

var
form1 : tform;
vlu : variant;



then add a procedure to querry 's even beforeOpen

procedure tform1.query1BeforeOpen(......);
begin
query1.parambyname('prm').value := vlu; // assigning value held in variable to the param before the query opens
end;



then u can carry on changing the value of variable
close the querry and reopen it .



another way is just write the querry script like-
query1.sql.text := 'select * from animals where name = :PRM';
QUERY1.PARAMBYNAME('PRM').VALUE := 'LION';
QUERY1.OPEN;


i hope it must solve ur problem
Reply With Quote
  #3  
Old 01-04-2001, 09:44 PM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default RE: Query Parameter Question...?

there are two parts
first is writing the script with variable and another is using bind variable

eg-
for first you can say
query1.sql.text := 'select * from animals where name = ''' + edit1.text + '''';
query1.open;


another way is

query1.sql.text := 'select * from animals where name = rm';
here prm preceeded by colon sign signifies bind variable

second one is much better as it reduces the server time too


then comes the problem of assigning values to these bind variables
there are two ways for this also

first in case you open the same querry multiple time in same form with different param values then you can create a global variable in form say

var
form1 : tform;
vlu : variant;



then add a procedure to querry 's even beforeOpen

procedure tform1.query1BeforeOpen(......);
begin
query1.parambyname('prm').value := vlu; // assigning value held in variable to the param before the query opens
end;



then u can carry on changing the value of variable
close the querry and reopen it .



another way is just write the querry script like-
query1.sql.text := 'select * from animals where name = :PRM';
QUERY1.PARAMBYNAME('PRM').VALUE := 'LION';
QUERY1.OPEN;


i hope it must solve ur problem
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 02:00 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.