如何实现update时的字段名用变量代替(20分)

  • 主题发起人 主题发起人 jackson_wu
  • 开始时间 开始时间
J

jackson_wu

Unregistered / Unconfirmed
GUEST, unregistred user!
ADOQuery1数据集内容<br>code &nbsp; &nbsp;bumo &nbsp; &nbsp;sl &nbsp; &nbsp;Field<br>0001 &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; 100 &nbsp; PV1<br>0001 &nbsp; &nbsp;A &nbsp; &nbsp; &nbsp; 100 &nbsp; PV20<br>以下程序实现的功能是:取出ADOQuery1中每一行数据对ADOQuery2进行更新<br>报错:不正常地定义参数对象,提供了不一致或不完整的信息.<br>是不是因为'update xseik set :strField=:sl 这一句的问题啊<br> &nbsp; &nbsp; &nbsp; ADOQuery2.SQL.Add('update xseik set :strField=:sl where CODE=:strcode and '+' bumo=:strbumo and skubu =0 and fixlevel=1 ');<br><br><br>procedure TFrmSeikRecovery.Button2Click(Sender: TObject);<br>var<br> &nbsp;strcode,strbumo,strField:string;<br> &nbsp;sl:double;<br>begin<br> &nbsp;ADOQuery1.First;<br> &nbsp;while not ADOQuery1.Eof do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; strcode:=ADOQuery1.Fields[0].Value;<br> &nbsp; &nbsp; &nbsp; strbumo:=ADOQuery1.Fields[1].Value;<br> &nbsp; &nbsp; &nbsp; sl:=ADOQuery1.Fields[2].Value;<br> &nbsp; &nbsp; &nbsp; strField:=ADOQuery1.Fields[4].Value;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('strcode').Value:=strcode;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('strbumo').Value:=strbumo;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('sl').Value:=sl;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('strField').Value:=strField;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Close;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.SQL.Clear;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.SQL.Add('update xseik set :strField=:sl where CODE=:strcode and '+' bumo=:strbumo and skubu =0 and fixlevel=1 ');<br> &nbsp; &nbsp; &nbsp; try<br> &nbsp; &nbsp; &nbsp; &nbsp; ADOQuery2.ExecSQL;<br> &nbsp; &nbsp; &nbsp; except<br> &nbsp; &nbsp; &nbsp; &nbsp; showmessage('连接数据库失败!!!!');<br> &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; //showmessage(floattostr(sl));<br> &nbsp; &nbsp; &nbsp; ADOQuery1.Next;<br> &nbsp; &nbsp;end;<br>end;
 
ADOQuery2.SQL.Add('update xseik set ' + 变量 + '=:sl where CODE=:strcode and '+' bumo=:strbumo and skubu =0 and fixlevel=1 ');<br>即:<br>procedure TFrmSeikRecovery.Button2Click(Sender: TObject);<br>var<br> &nbsp;strcode,strbumo,strField:string;<br> &nbsp;sl:double;<br>begin<br> &nbsp;ADOQuery1.First;<br> &nbsp;while not ADOQuery1.Eof do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; strcode:=ADOQuery1.Fields[0].Value;<br> &nbsp; &nbsp; &nbsp; strbumo:=ADOQuery1.Fields[1].Value;<br> &nbsp; &nbsp; &nbsp; sl:=ADOQuery1.Fields[2].Value;<br> &nbsp; &nbsp; &nbsp; strField:=ADOQuery1.Fields[4].Value;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('strcode').Value:=strcode;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('strbumo').Value:=strbumo;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Parameters.ParamByName('sl').Value:=sl;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.Close;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.SQL.Clear;<br> &nbsp; &nbsp; &nbsp; ADOQuery2.SQL.Add('update xseik set ' + strField + '=:sl where CODE=:strcode and '+' bumo=:strbumo and skubu =0 and fixlevel=1 ');<br> &nbsp; &nbsp; &nbsp; try<br> &nbsp; &nbsp; &nbsp; &nbsp; ADOQuery2.ExecSQL;<br> &nbsp; &nbsp; &nbsp; except<br> &nbsp; &nbsp; &nbsp; &nbsp; showmessage('连接数据库失败!!!!');<br> &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp; //showmessage(floattostr(sl));<br> &nbsp; &nbsp; &nbsp; ADOQuery1.Next;<br> &nbsp; &nbsp;end;<br>end;
 
谢谢,<br>给分
 
后退
顶部