如果动态的SQL,自然参数也要动态呀!!下面是我的一个例子
datamodule1.Qexesql.Close;
datamodule1.Qexesql.sql.clear;
datamodule1.qexesql.Params.Clear;
datamodule1.qexesql.Params.CreateParam (ftString,'stocker',ptInput);
datamodule1.qexesql.Params.CreateParam (ftString,'stock',ptInput);
datamodule1.qexesql.Params.CreateParam (ftString,'work_date',ptInput);
datamodule1.qexesql.Params.CreateParam (ftInteger,'work_num',ptInput);
datamodule1.qexesql.Params.CreateParam (ftfloat,'work_price',ptInput);
datamodule1.qexesql.Params.CreateParam (ftfloat,'work_fee',ptInput);
datamodule1.qexesql.Params.CreateParam (ftString,'info_guid',ptInput);
datamodule1.qexesql.sql.add('insert into tb_object_1154(ob_object_id,ob_release_date_1154,f1_1154,f2_1154,f3_1154,f5_1154,f6_1154,f7_1154,f10_1154,f13_1154)');
datamodule1.qexesql.sql.add('values (f_createclassid(),"NOW",:stocker,:work_date,:stock,"3",:work_num,:work_price,:work_fee,:info_guid)');
datamodule1.qexesql.ParamByName ('stocker').asstring:=stock_usr;
datamodule1.qexesql.ParamByName ('stock').asstring:=stock_id;
datamodule1.qexesql.ParamByName ('work_num').asinteger:=access_num;
datamodule1.qexesql.ParamByName ('work_date').asstring:=work_date;
datamodule1.qexesql.ParamByName ('work_price').asfloat:=work_price;
datamodule1.qexesql.ParamByName ('work_fee').asfloat:=access_fee;
datamodule1.qexesql.ParamByName ('info_guid').asstring:=info_guid;
然后执行datamodule1.qexesql.execsql;