同时更新多个表的时候用事务啊,要不有的表更新了有的表失败了怎么办?
代码如下:(没有密码的时候可以执行,去掉事务相关的语句也可以执行)
with ADOQuery4 do
begin
proId:=ADOQuery2.FieldByName('proId').AsString;
try
Connection.BeginTrans;
sql.Text:='insert into proIndex(proId,matId,num,[time]) values(%s,%s,%s,''%s'')';
sql.Text:=Format(sql.Text,[proId,FMatId[combobox2.ItemIndex],Edit4.Text,DateTimeToStr(now)]);
ExecSQL;
sql.Text:='update product set hasset=''是'' where proId=%s';
sql.Text:=Format(sql.Text,[proId]);
ExecSQL;
Connection.CommitTrans;
ShowMessage('添加成功!');
except
Connection.RollbackTrans;
ShowMessage('添加失败!');
end;
end;