我现在使用ADO(VC)调用一个存储过程,
CREATE PROCEDURE p_GetImport
(
@id int = 1
)
AS
  SELECT * from table1 where id= @id
  RETURN 0
GO
我可以忽略这个参数吗?我可以告诉ADO我将使用缺省参数吗?
在查询分析器中,我可以这样
EXEC @RC =  p_GetImport DEFAULT

EXEC @RC =  p_GetImport
在VC6 程序中如何实现

解决方案 »

  1.   

    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    VOID PrintProviderError(_ConnectionPtr pConnection)
    {
    // Print Provider Errors from Connection object.
    // pErr is a record object in the Connection's Error collection.
    ErrorPtr  pErr = NULL;
    long      nCount = 0;
    long      i = 0; if( (pConnection->Errors->Count) > 0)
    {
    nCount = pConnection->Errors->Count;
    // Collection ranges from 0 to nCount -1.
    for(i = 0; i < nCount; i++)
    {
    pErr = pConnection->Errors->GetItem(i);
    printf("\n\t Error number: %x\t%s", pErr->Number, (LPCSTR)pErr->Description);
    }
    }
    }
    /*
    CREATE PROCEDURE "ONEGA"."TestProc1" 
    (
    p_out OUT numeric,
    p_id IN numeric DEFAULT 1
    )
    IS
    BEGIN
    p_out:= p_id + 1234;return;
    END ;
     */
    int main(int argc, char* argv[])
    {
    printf("Use ADO to open Oracle!\n");
    CoInitialize(NULL);
    _ConnectionPtr pConn("ADODB.Connection");
    try
    {
    _CommandPtr    Cmd1;
    Cmd1.CreateInstance( __uuidof( Command ) );
    _ParameterPtr outParam=NULL;
    _RecordsetPtr  pRst("ADODB.Recordset");
    pConn->Open("Provider=OraOLEDB.Oracle;Data Source=workdb;User Id=Onega;Password=sa;"
    ,"","",adConnectUnspecified);
    Cmd1->ActiveConnection = pConn;
    Cmd1->CommandText      = "{call ONEGA.TestProc1( ?)}";
    Cmd1->CommandType      = adCmdText;
    outParam = Cmd1->CreateParameter("p_out",adInteger,adParamOutput,sizeof(int));
    Cmd1->Parameters->Append(outParam);
    Cmd1->Execute(NULL,NULL,adExecuteNoRecords);
    long p2=Cmd1->Parameters->Item["p_out"]->Value;
    printf("p2= %d,\n",p2);
    pConn->Close();
    }
    catch(_com_error &e)
    {
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("\nCOM error occurred, Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    PrintProviderError(pConn);
    }
    ::CoUninitialize();
    printf("program end.\n");
    return 0;
    }