我在一个form上放了storedproc1,datasource1,dbgrid1
并让他们相互关联
datasource1.dataset->storedproc1
dbgrid1.datasource->datasource1
我在调用storedproc1.open 时提示出错
‘err creating cursor handle'
不知为何

解决方案 »

  1.   

    storedproc一般是用来执行存储过程的。在程序一般也不是用open方法,而是用execute,如果需要参数或有返回值,可操作paramters属性。
      

  2.   

    用storedproc.execute
    不用open;
      

  3.   

    先谢谢了
    用execute后不会显示错误
    但是和dbgrid里面却没有显示结果
      

  4.   

    你可以使用ADOQuery来执行存储过程
    !这样你就很容易得到结果!
      

  5.   

    据我所知,StoredProc是TCustomADODataset的子类,是可以返回数据集的。
    不返回数据集应该用Execute,返回数据集应该是可以用Open的。
    也许要Prepared?机器刚刚重装,没来得及测试。
      

  6.   

    在query的sqlstring中:select * from procedurename
      

  7.   

    我把我的具体作法贴出来
    我在form上放了一个tstoredproc 和一个dbgrid 以及一个datasoure
    分别设StoredProc1.datasource:=datasource1;和dbgrid.datasoure:=datasource1; 
    然后有下面的代码
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    StoredProc1.Procname:='get_capital';
    StoredProc1.Prepare;
    StoredProc1.ParamByName('capitalname').AsString:='beijing';
    StoredProc1.Open;//用execproc后不会出错但是和datasource相关联的dbgrid里面没有数据显示
    end;
    运行的时候出错
    project1.exe raised expectation class ENoResultSet with message 'err createing cursor handle' process stopped .Use step or run to continue
    存储过程的metadata如下:
    COMMIT WORK;
    SET AUTODDL OFF;
    SET TERM ^ ;/* Stored procedures */CREATE PROCEDURE "GET_CAPITAL" 
    (
      "COUNTRYNAME" CHAR(20)
    )
    RETURNS
    (
      "CAPITAL" CHAR(10)
    )
    AS
    BEGIN EXIT; END ^
    ALTER PROCEDURE "GET_CAPITAL" 
    (
      "COUNTRYNAME" CHAR(20)
    )
    RETURNS
    (
      "CAPITAL" CHAR(10)
    )
    AS
    begin
    for select capital
     from cuntry
    where name=:countryname
     into:capital
    do
     suspend;
    end
     ^SET TERM ; ^
    COMMIT WORK;
    SET AUTODDL ON;