Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. OLE DB and return value from stored procedure

OLE DB and return value from stored procedure

Scheduled Pinned Locked Moved Database
databasecomquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kurlyak
    wrote on last edited by
    #1

    I have code and return value == 0. Why? It must be 99!

    ALTER PROCEDURE [dbo].[myproc]
    (
    @mykod INT
    )
    RETURNS INT
    AS
    BEGIN
    select * from table1 where kod=@mykod
    RETURN 99
    END

    //----------------------------------

    ICommandText* pICommandText;
    hr = pIDBCreateCommand->CreateCommand(NULL, IID_ICommandText,(IUnknown**) &pICommandText);
    if (FAILED(hr)) AfxMessageBox("Command Create Command Failed");

    WCHAR* wSQLString = L"{?=CALL myproc(?)}";

    pICommandText->SetCommandText(DBGUID_DBSQL, wSQLString);

    SPROCPARAMS sprocparams = {0, 2};

    // Command parameter data.
    DBPARAMS            Params;
    const ULONG         nParams = 2;
    

    //-----------------

    typedef struct tagSPROCPARAMS
    {
    long lReturnValue;
    long lkodValue;
    } SPROCPARAMS;

    DBBINDING acDBBinding[nParams];
    DBBINDSTATUS acDBBindStatus[nParams];

    for (ULONG i = 0; i < nParams; i++)
        {
        acDBBinding\[i\].obLength = 0;
        acDBBinding\[i\].obStatus = 0;
        acDBBinding\[i\].pTypeInfo = NULL;
        acDBBinding\[i\].pObject = NULL;
        acDBBinding\[i\].pBindExt = NULL;
        acDBBinding\[i\].dwPart = DBPART\_VALUE;
        acDBBinding\[i\].dwMemOwner = DBMEMOWNER\_CLIENTOWNED;
        acDBBinding\[i\].dwFlags = 0;
        acDBBinding\[i\].bScale = 0;
        }
    
    
    acDBBinding\[0\].iOrdinal = 1;
    acDBBinding\[0\].obValue = offsetof(SPROCPARAMS, lReturnValue);
    acDBBinding\[0\].eParamIO = DBPARAMIO\_OUTPUT;
    acDBBinding\[0\].cbMaxLen = sizeof(long);
    acDBBinding\[0\].wType = DBTYPE\_I4;
    acDBBinding\[0\].bPrecision = 11;
    
    
    acDBBinding\[1\].iOrdinal = 2;
    acDBBinding\[1\].obValue = offsetof(SPROCPARAMS, lkodValue);
    acDBBinding\[1\].eParamIO = DBPARAMIO\_INPUT;
    acDBBinding\[1\].cbMaxLen = sizeof(long);
    acDBBinding\[1\].wType = DBTYPE\_I4;
    acDBBinding\[1\].bPrecision = 11;
    
    
    // Get the IAccessor interface, then create the accessor for
    // the defined parameters.
    
    IAccessor\*  pIAccessor; 
    

    HACCESSOR hAccessor;

    pICommandText->QueryInterface(IID_IAccessor,
    (void**) &pIAccessor);
    if(FAILED(hr)) AfxMessageBox("Failed Query Interface IId_IAccessor");

    hr = pIAccessor->CreateAccessor(DBACCESSOR\_PARAMETERDATA,
        nParams, acDBBinding, sizeof(SPROCPARAMS), &hAccessor,
        acDBBindStatus);
    if(FAILED(hr)) AfxMessageBox("Failed Create Accessor");
    
    // Fill the DBPARAMS structure for the command execution.
    Params.pData = &sprocpa
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups