Home > Back-end >  Delphi under the great god help me to debug for cycle not insert properly
Delphi under the great god help me to debug for cycle not insert properly

Time:09-27

Procedure TfrmMain. NcaculateClick (Sender: TObject);
Var
Bid1: TBid;
Estimate: TEstimate;
The begin
ADOQuery1. Close;
ADOQuery1. SQL. The Clear;
ADOQuery1. SQL. Text:='select * from the Bid';
ADOQuery1. Open;
ADOQuery2. Close;
ADOQuery2. SQL. The Clear;
ADOQuery2. SQL. Add (' insert into Estimate (CompanyNo EstimateFactor) '+
'values (CompanyNo, : EstimateFactor)');
ADOQuery1. First;
While not ADOQuery1. Eof do
The begin
Bid1.Com panyNo:=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.Com panyNo:=bid1.Com panyNo;
ADOQuery2. The Parameters. ParamByName (' CompanyNo.) Value:=bid1.Com panyNo;
ADOQuery2. The Parameters. ParamByName (' EstimateFactor). Value:=estimate. EstimateFactor;
ADOQuery2. ExecSQL;
ADOQuery1. Next;
The end;
ADOQuery1. Close;
The end;

Cycle seemed to do only once, because of an error cannot create duplicate values

CodePudding user response:

Step through the first take a look at where the error,

CodePudding user response:

Procedure TForm1. Button5Click (Sender: TObject);
Var
Bid1: TBid;
Estimate: TEstimate;
SQLSTR, TMP: string;
The begin
ADOQuery1. Close;
ADOQuery1. SQL. The Clear;
ADOQuery1. SQL. Text:='select * from the Bid';
ADOQuery1. Open;
ADOQuery2. Close;
ADOQuery2. SQL. The Clear;
: SQLSTR="insert into Estimate (CompanyNo EstimateFactor) values (' % s', '% s')'.

ADOQuery1. First;
While not ADOQuery1. Eof do
The begin
Bid1.Com panyNo:=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.Com panyNo:=bid1.Com panyNo;

TMP:=Format (SQLSTR, [bid1.Com panyNo, estimate. EstimateFactor]);
ADOQuery2. SQLSTR. Text=TMP;
Try
ADOQuery2. ExecSQL;
Except,
////debugging to join an error prompt
The end;
ADOQuery1. Next;
The end;
ADOQuery1. Close;

CodePudding user response:

Estimation is your two record type assignment after inserted into the database of the problem,
Can be inserted before the increase showmessage (TMP), check the inserted data is correct or on a test database,

CodePudding user response:

 procedure TfrmMain. NcaculateClick (Sender: TObject); 
Var SQL, S1, S2, S3, ID, ID1: string;
L: integer;
The begin
DateTimetoString (ID, 'yymmddhhnnss, now);
ADOQuery1. Close;
ADOQuery1. SQL. The Clear;
ADOQuery1. SQL. Text:='select * from the Bid';
ADOQuery1. Open;
ADOQuery2. Close;
L:=100
While not ADOQuery1. Eof do
The begin
ID1: ID=+ IntToStr (L);
S1:=ADOQuery1 FieldByName (' CompanyNo.) AsString;
S2:=ADOQuery1 FieldByName (' Quantity '). AsInteger;
S3:=ADOQuery1 FieldByName (' MaterialPrice). AsInteger;
SQL:="INSERT INTO the table name (field 1, 2, field 3, ID) '+
'VALUES (' + # 39 + S1 + # 39 +', '+ # 39 + S2 + # 39 +', '+ # 39 + S3 + # 39 +', '+ # 39 + ID1 + # 39 +') '.
ADOQuery2. SQL. Text:=SQL;
ADOQuery2. ExecSQL;
ADOQuery1. Next;
L:=L + 1;
The end;
ADOQuery1. Close;
The end;


Recommend the use of SQL statements inserted, code for reference only,
  • Related