写了一个存储过程(adostoredproc)返回记录时总是,报can't not perform this 
when dataset is closed?

解决方案 »

  1.   

    adoconnection 打开了吗?adoconnection.connect := true;
      

  2.   

    我在try 语句写adoconnction的连接的及adostroedproc.execproc,而且通过了,
    但用adostroedproc.state试了一下,竟然是dsinactive,可能没连上???
      

  3.   

    我又试了一次,连接是成功的,不知是否是bug,我用的是6.0
      

  4.   

    晕了,越来越糊涂了,
    加个adoconnection空间,选中connection属性,选好驱动,数据库,密码等属性,测试连接,成功!
    然后选中connected:true,竟弹出:连接失败!!!!!
    为什么会这样?
      

  5.   

    不知道你用adoconnection得connectionstring属性中是怎么设置的
      

  6.   

    procedure Tfrm_PriceQuery.Research_btnClick(Sender: TObject);
    var
        _key     :string;
        _brand   :string;
        _name    :string;
        _origin  :string;
        _catalog :string;
        _adoconn  :TADOCONNECTION;
        _adoproc  :TADOSTOREDPROC;
        ...    
    begin
         try
         begin
             _adoconn:=TADOCONNECTION.Create(nil);
             _adoproc:=TADOSTOREDPROC.Create(nil);                     _doconnectionString:='Provider=SQLOLEDB.1;Password=****;Persist              Security Info=True;User ID=*****;
    Initial Catalog=****;Data Source=****;';
             _adoconn.LoginPrompt:=false;
             _adoconn.Connected:=true;
         end
         except
         begin
            showmessage('连接失败');
            exit;
         end;
         end;
         _key  :=trim(Cyberedit1.Text);
         _brand:=trim(CyberEdit2.Text);
         _name :=trim(CyberEdit3.Text);
         _catalog:=trim(CatalogCOB.SelText);
         _origin :=trim(OriginCOB.SelText);
         _adoproc.Connection:=_adoconn;
         _adoproc.ProcedureName:='sp_PriceQuery';
         _adoproc.Parameters.CreateParameter('key',ftString,pdinput,50,_key);
         _adoproc.Parameters.CreateParameter('brand',ftString,pdinput,50,_brand);
         _adoproc.Parameters.CreateParameter('name',ftString,pdinput,50,_name);
         _adoproc.Parameters.CreateParameter('catalog',ftString,pdinput,50,_catalog);
         _adoproc.Parameters.CreateParameter('origin',ftString,pdinput,255,_origin);
         _adoproc.Parameters.CreateParameter('result',ftString,pdoutput,20,null);     try
         begin
             _adoproc.Prepared:=true;
             _adoproc.ExecProc;
         end
         except
         begin
             showmessage('失败');
             exit;
         end;
         end;
         if _adoproc.RecordCount>0 then
         begin
             while not _adoproc.Eof do
             begin
                 ....  
                 _adoproc.Next;
             end;
         end;
         _adoproc.Parameters.ParamByName('key').Free;
         _adoproc.Parameters.ParamByName('brand').Free;
         _adoproc.Parameters.ParamByName('name').Free;
         _adoproc.Parameters.ParamByName('catalog').Free;
         _adoproc.Parameters.ParamByName('origin').Free;
         _adoproc.Free;end;
    我试了几次了,连数据库时好象没多大问题,倒是在执行存储过程时有这个问题:
       oleexception: 语法错误或访问冲突????