Home > Back-end >  Delphi ADO controls, insert records into a database table, the second to make mistakes
Delphi ADO controls, insert records into a database table, the second to make mistakes

Time:10-24

Button ONCLICK event, for the first time can be successful, a second insertion, there will be: the Access violation at address 4 de43404 module in 'sqloledb. DLL', Read of address I novice, 00000018 for help

Procedure TForm1. Btn1Click (Sender: TObject);
Var
I: Extended;

The begin
If MessageDlg (' to new information, please? ', mtInformation mbOKCancel, 0)=mrOk then begin
Qry1. Close;
Qry1. SQL. The Clear;
Qry1. SQL. The Add (' select * from tb_stu_practice where stu_no='" + edt2. Text + "' ");
Qry1. Open;
If qry1. RecordCount=1 then the begin
Showmessage (' have records of the same student id! Don't let it repeat new, use the save changes');
exit;
end;

With sp1 do begin
The Close;
ProcedureName:='sp_tb_add_stu';
The Parameters. Refresh;

If (edt2. Text=' ') or (edt1. Text=' ') or (edt8. Text=' ') then the begin
ShowMessage (' blue as required);
exit;
End the else begin
The Parameters. ParamByName (' @ stu_name). Value:=TrimLeft (edt1. Text);
If TryStrToFloat (Edt2. The Text, I) then the begin
The Parameters. ParamByName (' @ stu_no '). The value:=TrimLeft (edt2. Text);
End the else begin
ShowMessage (' should be numeric type);
The Exit;
end;
If TryStrToFloat (Edt8. The Text, I) then the begin
The Parameters. ParamByName (' @ stu_id) value:=TrimLeft (edt8. Text);
End the else begin
ShowMessage (' should be numeric type);
The Exit;
end;
end;
If edt4. Text<> 'then the begin
If (edt4. Text='female') or (edt4. Text='male') then
The Parameters. ParamByName (' @ stu_sex '). The value:=TrimLeft (edt4. Text)
The else begin
ShowMessage (' "male" or "female" empty ");
The Exit;
end;
End the else Parameters. ParamByName (' @ stu_sex). Value:=null;

If edt5. Text<> 'then the begin
If (TryStrToFloat (Edt5. The Text, I)) and (StrToInt (Edt5. Text) & gt;=1) and (STRTOINT (edt5. Text) & lt;=130) then
The Parameters. ParamByName (' @ stu_age '). The value:=TrimLeft (edt5. Text)
The else begin
ShowMessage (' between 1 to 130 Numbers or empty ');
The Exit;
end;
End the else Parameters. ParamByName (' @ stu_age). Value:=null;
If edt6. Text<> 'then the begin
If (TryStrToFloat (Edt6. The Text, I)) then
The Parameters. ParamByName (' @ les_id '). The value:=TrimLeft (edt6. Text)
The else begin
ShowMessage (' les_id for Numbers or null).
The Exit;
end;
End the else Parameters. ParamByName (' @ les_id). Value:=null;

If edt7. Text & lt;> "' then
The Parameters. ParamByName (' @ inclass '). The value:=TrimLeft (edt7. Text)
The else
The Parameters. ParamByName (' @ inclass '). The value:=null;
Prepared:=True;
ExecProc;
End
ShowMessage (' new 'success);
The end;

end;

CodePudding user response:

That the fault?

CodePudding user response:

Debug it and see where the fault,

CodePudding user response:

Pay attention to the refresh data set

CodePudding user response:

Step by step, trace to the second click the new button, went straight to the end, the error is: the Access violation at address 4 de43404 module in 'sqloledb. DLL', the Read of because the address is 00000018 SP1 and qry1 Shared a datasource, or DBGRID not clear? Why use listview display can

CodePudding user response:

reference 4 floor cuipan1 response:
. Maybe it's because qry1 SP1 Shared a datasource

The separate with you to try it

CodePudding user response:

This USES a stored procedure, you separate the content, one at a time debugging, see a problem out there,

CodePudding user response:

Query and insert to update the data as far as possible use SQL statements to write such a safer, writing queries in ado controls may not stable, sometimes before they met in control after writing SQL statements and then use ado [Parameters. ParamByName (' @ stu_age). The value] to query can also beginning in the later modify software don't know what reason can't query out, finally had to switch to write SQL statements in the program,
  • Related