按钮ONCLICK事件,第一次可以成功,第二次插入时,会出现:Access violation at address 4DE43404 in module 'sqloledb.dll', Read of address 00000018 本人新手,求帮助procedure TForm1.btn1Click(Sender: TObject);
var
i:Extended;begin
if MessageDlg('要新建资料吗吗?',mtInformation,mbOKCancel,0) = mrOk then begin
qry1.Close;
qry1.SQL.Clear ;
qry1.SQL.Add('select * from tb_stu_practice where stu_no = '''+edt2.text+'''');
qry1.open;
if qry1.recordCount= 1 then begin
showmessage('存在相同学号的记录!不能重复新建,可用save修改');
exit;
end; with sp1 do begin
Close;
procedureName:='sp_tb_add_stu';
Parameters.Refresh; if (edt2.Text='') or (edt1.Text='')or (edt8.Text='')then begin
ShowMessage('蓝色为必填');
exit;
end else begin
Parameters.ParamByName('@stu_name').value:=TrimLeft(edt1.Text);
if TryStrToFloat(Edt2.Text, i) then begin
Parameters.ParamByName('@stu_no').value:= TrimLeft(edt2.Text);
end else begin
ShowMessage('应为数字类型');
Exit;
end;
if TryStrToFloat(Edt8.Text, i) then begin
Parameters.ParamByName('@stu_id').value:= TrimLeft(edt8.Text);
end else begin
ShowMessage('应为数字类型');
Exit;
end;
end;
if edt4.Text<>'' then begin
if (edt4.Text='女')or(edt4.Text='男') then
Parameters.ParamByName('@stu_sex').value:= TrimLeft(edt4.Text)
else begin
ShowMessage('“男”“女”或者为空');
Exit ;
end;
end else Parameters.ParamByName('@stu_sex').value:= null; if edt5.Text<>'' then begin
if (TryStrToFloat(Edt5.Text, i))and (StrToInt(edt5.Text)>=1)and (STRTOINT(edt5.Text)<=130)then
Parameters.ParamByName('@stu_age').value:= TrimLeft(edt5.Text)
else begin
ShowMessage('1到130之间的数字或者为空');
Exit;
end;
end else Parameters.ParamByName('@stu_age').value:= null;
if edt6.Text<>'' then begin
if (TryStrToFloat(Edt6.Text, i)) then
Parameters.ParamByName('@les_id').value:= TrimLeft(edt6.Text)
else begin
ShowMessage('les_id为数字或者为空');
Exit;
end;
end else Parameters.ParamByName('@les_id').value:= null; if edt7.Text <> ''then
Parameters.ParamByName('@inclass').value:= TrimLeft(edt7.Text)
else
Parameters.ParamByName('@inclass').value:= null;
Prepared:=True;
ExecProc ;
end
ShowMessage('新建成功');
end ;end;
var
i:Extended;begin
if MessageDlg('要新建资料吗吗?',mtInformation,mbOKCancel,0) = mrOk then begin
qry1.Close;
qry1.SQL.Clear ;
qry1.SQL.Add('select * from tb_stu_practice where stu_no = '''+edt2.text+'''');
qry1.open;
if qry1.recordCount= 1 then begin
showmessage('存在相同学号的记录!不能重复新建,可用save修改');
exit;
end; with sp1 do begin
Close;
procedureName:='sp_tb_add_stu';
Parameters.Refresh; if (edt2.Text='') or (edt1.Text='')or (edt8.Text='')then begin
ShowMessage('蓝色为必填');
exit;
end else begin
Parameters.ParamByName('@stu_name').value:=TrimLeft(edt1.Text);
if TryStrToFloat(Edt2.Text, i) then begin
Parameters.ParamByName('@stu_no').value:= TrimLeft(edt2.Text);
end else begin
ShowMessage('应为数字类型');
Exit;
end;
if TryStrToFloat(Edt8.Text, i) then begin
Parameters.ParamByName('@stu_id').value:= TrimLeft(edt8.Text);
end else begin
ShowMessage('应为数字类型');
Exit;
end;
end;
if edt4.Text<>'' then begin
if (edt4.Text='女')or(edt4.Text='男') then
Parameters.ParamByName('@stu_sex').value:= TrimLeft(edt4.Text)
else begin
ShowMessage('“男”“女”或者为空');
Exit ;
end;
end else Parameters.ParamByName('@stu_sex').value:= null; if edt5.Text<>'' then begin
if (TryStrToFloat(Edt5.Text, i))and (StrToInt(edt5.Text)>=1)and (STRTOINT(edt5.Text)<=130)then
Parameters.ParamByName('@stu_age').value:= TrimLeft(edt5.Text)
else begin
ShowMessage('1到130之间的数字或者为空');
Exit;
end;
end else Parameters.ParamByName('@stu_age').value:= null;
if edt6.Text<>'' then begin
if (TryStrToFloat(Edt6.Text, i)) then
Parameters.ParamByName('@les_id').value:= TrimLeft(edt6.Text)
else begin
ShowMessage('les_id为数字或者为空');
Exit;
end;
end else Parameters.ParamByName('@les_id').value:= null; if edt7.Text <> ''then
Parameters.ParamByName('@inclass').value:= TrimLeft(edt7.Text)
else
Parameters.ParamByName('@inclass').value:= null;
Prepared:=True;
ExecProc ;
end
ShowMessage('新建成功');
end ;end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货