我的保存代码:
with DataModule1 do
begin
if not Database1.Connected then
exit;
if saveButton_choice=1 then //选择保存第一张表
begin
with table1 do
begin
Database1.StartTransaction;
try
ApplyUpdates;
Database1.Commit;
except
application.MessageBox('不能重复输入,请重新输入再保存!','确认',MB_OK);
Database1.Rollback;
raise;
end;
commitupdates;
end;
end; //以上可以执行保存第一张表!
if saveButton_choice=2 then //选择保存第二张表
begin
with table2 do
begin
Database1.StartTransaction;
try
ApplyUpdates; //这里出错!!!
Database1.Commit;
except
application.MessageBox('不能重复输入,请重新输入再保存!','确认',MB_OK);
Database1.Rollback;
raise;
end;
commitupdates;
end;
end;
end;
为什么两部分代码一样,却不能进行同样的操作???
with DataModule1 do
begin
if not Database1.Connected then
exit;
if saveButton_choice=1 then //选择保存第一张表
begin
with table1 do
begin
Database1.StartTransaction;
try
ApplyUpdates;
Database1.Commit;
except
application.MessageBox('不能重复输入,请重新输入再保存!','确认',MB_OK);
Database1.Rollback;
raise;
end;
commitupdates;
end;
end; //以上可以执行保存第一张表!
if saveButton_choice=2 then //选择保存第二张表
begin
with table2 do
begin
Database1.StartTransaction;
try
ApplyUpdates; //这里出错!!!
Database1.Commit;
except
application.MessageBox('不能重复输入,请重新输入再保存!','确认',MB_OK);
Database1.Rollback;
raise;
end;
commitupdates;
end;
end;
end;
为什么两部分代码一样,却不能进行同样的操作???
给两个建议
1、把代码分离开,分为两个按钮下的事件处理代码
2、将所有的 WITH 去掉