Home > Back-end >  How to create TParameters parameters
How to create TParameters parameters

Time:10-15

How to create TParameters parameters, then ADOQuery object, using create TParameters parameters,
Procedure TForm1. Btn_3Click (Sender: TObject);
Var
Ps: TParameters;
P1, p2, p3: TParameter;
The begin
Ps:=TParameters. Create (nil, TParameter);
//p1:=ps. CreateParameter (' f1 'ftInteger, pdInput, 4, 1);
//p2:=ps. CreateParameter (' f2 'ftString pdInput, 10,' a ');
//p3:=ps. CreateParameter (' f3 'ftFloat pdInput, 8,1.3);//use the following not Add

P1:=ps. AddParameter;
P1. Name:='f1';
P1. DataType:=ftInteger;
P1. Direction:=pdInput;
P1. The Value:=1;

P2:=ps. AddParameter;
P2. Name:='f2';
P2. DataType:=ftString;
P2. Direction:=pdInput;
P2. Value:='a';

P3:=ps. AddParameter;
P3. Name:='f3';
P3. DataType:=ftFloat;
P3. Direction:=pdInput;
P3. Value:=2.3;

Qry1. Close;
Qry1. SQL. The Clear;
Qry1. SQL. The Add (' insert t3 (f1, f2 and f3) values (: : f1, f2, f3) ');

//specified here in qry1 parameter values, to create their own parameters, because want to take the following assignment part,
//write a generic method, here to do a test with
Qry1. The Parameters. ParamByName (' f1 '). The Value:=ps [0]. Value;
Qry1. The Parameters. ParamByName (' f2 '). The Value:=ps [1]. The Value;
Qry1. The Parameters. ParamByName (' f3 '). The Value:=ps [2]. The Value;
Qry1. ExecSQL;
end;

CodePudding user response:

Insert into table1 (id, name) values (id: value)

Qry1. ParamByName (' id '). ParamType:=ptInput;
Qry1. ParamByName (" id "). The DataType:=ftInteger;
Qry1. ParamByName (' id '). AsInteger:=123;

Qry1. ParamByName (' name '). ParamType:=ptInput;
Qry1. ParamByName (' name '). The DataType:=ftString;
Qry1. ParamByName (' name '). AsString:='123 dd';


That meet the requirements above

CodePudding user response:

Don't meet
I want to create your own parameters, such as myParameters, then give myParameters assignment
Then qry1 the parameters in the, in turn in the assignment of myParameters to qry1 the parameters in the assignment

CodePudding user response:

refer to the original poster yuimison response:
how to create TParameters parameters, then ADOQuery object, use the create TParameters parameters,
Procedure TForm1. Btn_3Click (Sender: TObject);
Var
Ps: TParameters;
P1, p2, p3: TParameter;
The begin
Ps:=TParameters. Create (nil, T...


Your SQL statements written must know parameter
Establish a ps (TParameters) first, and then assigned to the query can
Qry1. The Parameters:=ps

CodePudding user response:

I want to write to the parameter qry1 part a generic methods
PreparePara (qry: TADOQuery; Params: TParameters)
Var
I: integer;
The begin
For I:=0 to qry. The Parameters. Do the Count - 1
The begin
Qry. The Parameters [0]. Value:=params [0]. Value;
end;
end;

Like this, so you need to create the params preparePara parameters and then passed to the method

CodePudding user response:

Expect that master

CodePudding user response:

How no one to answer
  • Related