{增加记录按钮}
procedure TForm1.Button1Click(Sender: TObject);
begin //开始增加记录
adotable1.Insert; ////////////注意,你是Insert ,
end;{保存记录按钮}
procedure TForm1.Button2Click(Sender: TObject);
begin
if adotable1.state=dsedit then //////////要是你用adoTable1.Edit的话,这里的状态就是dsEdit了,要知道Insert与Edit是不同的,所以它的状态也就不同了,你也就if不到了,呵呵
begin
adotable1.Post;
end
else
begin
messagebox(form1.Handle,'您没有输入任何数据','提示',mb_ok+mb_iconinformation);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin //开始增加记录
adotable1.Insert; ////////////注意,你是Insert ,
end;{保存记录按钮}
procedure TForm1.Button2Click(Sender: TObject);
begin
if adotable1.state=dsedit then //////////要是你用adoTable1.Edit的话,这里的状态就是dsEdit了,要知道Insert与Edit是不同的,所以它的状态也就不同了,你也就if不到了,呵呵
begin
adotable1.Post;
end
else
begin
messagebox(form1.Handle,'您没有输入任何数据','提示',mb_ok+mb_iconinformation);
end;
end;
if adotable1.state in [dsedit,dsinsert] then
....
if adotable1.state in [dsedit,dsinsert] then
这样形式因为有可能处在编辑和插入状态,却没有输入任何数据;最好用if adotable1.Modified then ....这种形式来判断
1)你可能是希望先判断是否处于可编辑状态,只是为什么要做这样的判断?
2)你可能是希望处理数据的规则是否正确,这可以有很多办法。如:
A)提交前进行分析。
B)提交后处理异常,如果数据库设计时有约束关系的话,可能会触发异常。
C)还有更复杂的异常,尤其是多用户时。
D)最好是用事务处理,异常时回滚。
……