N
nlk2002
Unregistered / Unconfirmed
GUEST, unregistred user!
请看下面的程序
procedure TfrmMain.BtnSaveClick(Sender: TObject);
var
vTopicName,vAddres,vCompere,vAttendee,vMediaName,vConTent:String;
VMeetDate:String;
qry:TADOQuery;
Str:String;
begin
if Edit1.Text = '' then
begin
MessageDlg('会议主题不能为空',mtWarning,[mboK],0);
Edit1.SetFocus;
Exit;
end;
if Edit2.Text = '' then
begin
MessageDlg('会议地址不能为空',mtWarning,[mboK],0);
Edit2.SetFocus;
Exit;
end;
if Edit3.Text= '' then
begin
MessageDlg('主持人不能为空',mtWarning,[mboK],0);
Edit3.SetFocus;
Exit;
end;
if Edit4.Text = '' then
begin
MessageDlg('参加人员不能为空',mtWarning,[mboK],0);
Edit4.SetFocus;
Exit;
end;
if ComboBox1.Text = '' then
begin
MessageDlg('媒体不能为空',mtWarning,[mboK],0);
ComboBox1.SetFocus;
Exit;
end;
vTopicName:=Edit1.Text;
vAddres:=Edit2.Text;
vCompere:=Edit3.Text;
vAttendee:=Edit4.Text;
VMeetDate:=formatDateTime('yyyy-mm-dd',DateTimePicker1.dateTime );
vMediaName:=ComboBox1.Text;
vConTent:=Memo1.Text;
try
qry:=TADOQuery.Create(nil);
qry.ConnectionString:=FrmMyDm.ADOConn.ConnectionString;
qry.Connection.BeginTrans;
with qry do
begin
Close;
Sql.Clear;
Sql.Add('Insert into cbgl(TopicName,MeetDate,Addres,Compere,Attendee,'+
'MediaName,ConTent)'+
'Values('''+vTopicName+''','''+VMeetDate+''','+
' '''+vAddres+''','''+vCompere+''','''+vAttendee+''','''+vMediaName+''','+
' '''+vConTent+''' '+')');
str:=Sql.Text;
ExecSql;
frmMyDm.ADOConn.CommitTrans;
end;
except
FrmMyDm.ADOConn.RollbackTrans;
MessageDlg('数据不能保存,请联系管理员!',mtError,[mbOK],0);
exit;
end;
end;
end.
每次我BtnSaveClick,就会弹出“对象关闭时,操作不被允许“,为什么?
procedure TfrmMain.BtnSaveClick(Sender: TObject);
var
vTopicName,vAddres,vCompere,vAttendee,vMediaName,vConTent:String;
VMeetDate:String;
qry:TADOQuery;
Str:String;
begin
if Edit1.Text = '' then
begin
MessageDlg('会议主题不能为空',mtWarning,[mboK],0);
Edit1.SetFocus;
Exit;
end;
if Edit2.Text = '' then
begin
MessageDlg('会议地址不能为空',mtWarning,[mboK],0);
Edit2.SetFocus;
Exit;
end;
if Edit3.Text= '' then
begin
MessageDlg('主持人不能为空',mtWarning,[mboK],0);
Edit3.SetFocus;
Exit;
end;
if Edit4.Text = '' then
begin
MessageDlg('参加人员不能为空',mtWarning,[mboK],0);
Edit4.SetFocus;
Exit;
end;
if ComboBox1.Text = '' then
begin
MessageDlg('媒体不能为空',mtWarning,[mboK],0);
ComboBox1.SetFocus;
Exit;
end;
vTopicName:=Edit1.Text;
vAddres:=Edit2.Text;
vCompere:=Edit3.Text;
vAttendee:=Edit4.Text;
VMeetDate:=formatDateTime('yyyy-mm-dd',DateTimePicker1.dateTime );
vMediaName:=ComboBox1.Text;
vConTent:=Memo1.Text;
try
qry:=TADOQuery.Create(nil);
qry.ConnectionString:=FrmMyDm.ADOConn.ConnectionString;
qry.Connection.BeginTrans;
with qry do
begin
Close;
Sql.Clear;
Sql.Add('Insert into cbgl(TopicName,MeetDate,Addres,Compere,Attendee,'+
'MediaName,ConTent)'+
'Values('''+vTopicName+''','''+VMeetDate+''','+
' '''+vAddres+''','''+vCompere+''','''+vAttendee+''','''+vMediaName+''','+
' '''+vConTent+''' '+')');
str:=Sql.Text;
ExecSql;
frmMyDm.ADOConn.CommitTrans;
end;
except
FrmMyDm.ADOConn.RollbackTrans;
MessageDlg('数据不能保存,请联系管理员!',mtError,[mbOK],0);
exit;
end;
end;
end.
每次我BtnSaveClick,就会弹出“对象关闭时,操作不被允许“,为什么?