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 meetI 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: