Delphi sql 从一张表读取记录计算,然后插入另一张表 大神看看
procedureTfrmMain.NcaculateClick(Sender:TObject);varbid1:TBid;estimate:TEstimate;begi...
procedure TfrmMain.NcaculateClick(Sender: TObject);
var
bid1: TBid;
estimate: TEstimate;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := 'select * from Bid';
ADOQuery1.Open;
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('insert into Estimate(CompanyNo,EstimateFactor )'+
'values(:CompanyNo,:EstimateFactor)');
while not ADOQuery1.Eof do
begin
bid1.CompanyNo := ADOQuery1.FieldByName('CompanyNo').AsString;
bid1.Quantity := ADOQuery1.FieldByName('Quantity').AsInteger;
bid1.MaterialPrice := ADOQuery1.FieldByName('MaterialPrice').AsInteger;
bid1.Workdayprice := ADOQuery1.FieldByName('Workdayprice').AsInteger;
bid1.Mechanicalprice := ADOQuery1.FieldByName('Mechanicalprice').AsInteger;
bid1.OtherPrice := ADOQuery1.FieldByName('OtherPrice').AsInteger;
bid1.FinishTime := ADOQuery1.FieldByName('FinishTime').AsInteger;
estimate.EstimateFactor := 0.2*bid1.Quantity + 0.3*bid1.MaterialPrice
+ 0.2*bid1.Workdayprice + 0.15*bid1.Mechanicalprice + 0.05*bid1.OtherPrice
+ 0.1*bid1.FinishTime;
estimate.CompanyNo :=bid1.CompanyNo;
ADOQuery2.Parameters.ParamByName('CompanyNo').Value :=bid1.CompanyNo;
ADOQuery2.Parameters.ParamByName('EstimateFactor').Value := estimate.EstimateFactor;
ADOQuery2.ExecSQL;
end;
ADOQuery1.Close;
end;
为什么表Estimate 只有一条记录,因为报错 创建了重复的值。。。。。怎么解决啊,循环好像没实现功能 展开
var
bid1: TBid;
estimate: TEstimate;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := 'select * from Bid';
ADOQuery1.Open;
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('insert into Estimate(CompanyNo,EstimateFactor )'+
'values(:CompanyNo,:EstimateFactor)');
while not ADOQuery1.Eof do
begin
bid1.CompanyNo := ADOQuery1.FieldByName('CompanyNo').AsString;
bid1.Quantity := ADOQuery1.FieldByName('Quantity').AsInteger;
bid1.MaterialPrice := ADOQuery1.FieldByName('MaterialPrice').AsInteger;
bid1.Workdayprice := ADOQuery1.FieldByName('Workdayprice').AsInteger;
bid1.Mechanicalprice := ADOQuery1.FieldByName('Mechanicalprice').AsInteger;
bid1.OtherPrice := ADOQuery1.FieldByName('OtherPrice').AsInteger;
bid1.FinishTime := ADOQuery1.FieldByName('FinishTime').AsInteger;
estimate.EstimateFactor := 0.2*bid1.Quantity + 0.3*bid1.MaterialPrice
+ 0.2*bid1.Workdayprice + 0.15*bid1.Mechanicalprice + 0.05*bid1.OtherPrice
+ 0.1*bid1.FinishTime;
estimate.CompanyNo :=bid1.CompanyNo;
ADOQuery2.Parameters.ParamByName('CompanyNo').Value :=bid1.CompanyNo;
ADOQuery2.Parameters.ParamByName('EstimateFactor').Value := estimate.EstimateFactor;
ADOQuery2.ExecSQL;
end;
ADOQuery1.Close;
end;
为什么表Estimate 只有一条记录,因为报错 创建了重复的值。。。。。怎么解决啊,循环好像没实现功能 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |