今天碰到一个很奇怪的问题,我在一个AfterInsert时间中写入如下代码
procedure TDM.ADOQrBgAfterInsert(DataSet: TDataSet);
begin
  DataSet.FieldByName('ht_bianhao').AsString:=GetNextNo('400001','Bargain','ht_bianhao');
end;
出现如下错误
---------------------------
Debugger Exception Notification
---------------------------
Project BargainManage.exe raised exception class EOleException with message '无法在此会话中启动更多的事务。'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help   
---------------------------
但在另外的ADOQUERY的AfterInsert事件中写同样的代码却没问题,如
procedure TDM.ADOTbCusAfterInsert(DataSet: TDataSet);
begin
  DataSet.FieldByName('cus_bianhao').AsString:=GetNextNo('100001','customer','cus_bianhao');
end;
我的GetNextNo的函数代码如下
function TDM.GetNextNo(FirstNo, TableName,FieldName: string): string;
var
  TempADO:TADOQuery;
begin
  try
    TempADO:=TADOQuery.Create(self);
    with TempADO do
    begin
      Active:=false;
      Connection:=ADOConn;
      SQL.Clear;
      SQL.Add('select Max('+FieldName+') as bianhao from '+TableName);
      Prepared;
      Active:=true;
    end;
    if TempADO.FieldByName('bianhao').AsString='' then
      Result:=FirstNo
    else
      Result:=IntToStr(TempADO.FieldByName('bianhao').AsInteger+1);
  finally
    TempADO.Free;
    TempADO:=nil;
  end;end;

解决方案 »

  1.   

    不好意思,出错提示贴错了,出错提示如下所示
    ---------------------------
    Debugger Exception Notification
    ---------------------------
    Project BargainManage.exe raised exception class EOleException with message '发生未知错误。'. Process stopped. Use Step or Run to continue.
    ---------------------------
    OK   Help   
    ---------------------------
      

  2.   

    就是执行到  DataSet.FieldByName('ht_bianhao').AsString:=GetNextNo('400001','Bargain','ht_bianhao');的时候出错啊,函数的值是已经返回没问题了的,就是赋值的时候出错,不知道什么原因,郁闷
      

  3.   

    ht_bianhao字段是自动编号?或者没权限?
      

  4.   

    不是自动编号的啊,权限肯定也是有的啊,是不是我用了第三方插件有BUG啊