pjnutt 0 Newbie Poster

Hello,

I am attempting to make a stored procedure call to an ADO. I will paste in the try loop. Problem is code compiles and runs, however; the stored procedure never runs. It's supposed to create a row in the DB, and the row is never created. If I run the proc in a SQL query session, it runs succesfully, so I know that the proc is good. If anyone could be of any help, I would appreciate it. I am using sample code that I found at another site, my first thought was that I may have to use another function, not execute(), I'm at a loss.......

try
    {
        HRESULT result;

        //Connect to database
        result = ::CoInitialize(NULL);
        if (FAILED(result)) throw HookException("COM initialize failed.");

        result = connection.CreateInstance(__uuidof(Connection));
        if (FAILED(result)) throw HookException("Could not create connection instance.");

        result = connection->Open("DSN=WFC_DSN;UID=suprkron;PWD=skron96", "", "", adConnectUnspecified);
        if (FAILED(result)) throw HookException("Could not connect to database.");

        result = preparedCommand.CreateInstance(__uuidof(Command));
        if (FAILED(result)) throw HookException("Could not create prepared command.");

        preparedCommand->CommandText = "NGP_VALLABORACCT";
        preparedCommand->ActiveConnection = connection;
        preparedCommand->CommandType = adCmdStoredProc;

        //LL 1
        vLl1.vt = VT_I2;
        vLl1.iVal = ll1;
        inputParam = preparedCommand->CreateParameter(_bstr_t("1"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl1);
        preparedCommand->Parameters->Append(inputParam);
        //LL 2
        vLl2.vt = VT_I2;
        vLl2.iVal = ll2;
        inputParam = preparedCommand->CreateParameter(_bstr_t("2"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl2);
        preparedCommand->Parameters->Append(inputParam);
        //LL 3
        vLl3.vt = VT_I2;
        vLl3.iVal = ll3;
        inputParam = preparedCommand->CreateParameter(_bstr_t("3"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl3);
        preparedCommand->Parameters->Append(inputParam);
        //LL 4
        vLl4.vt = VT_I2;
        vLl4.iVal = ll4;
        inputParam = preparedCommand->CreateParameter(_bstr_t("4"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl4);
        preparedCommand->Parameters->Append(inputParam);
        //LL 5
        vLl5.vt = VT_I2;
        vLl5.iVal = ll5;
        inputParam = preparedCommand->CreateParameter(_bstr_t("5"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl5);
        preparedCommand->Parameters->Append(inputParam);
        //LL 6
        vLl6.vt = VT_I2;
        vLl6.iVal = ll6;
        inputParam = preparedCommand->CreateParameter(_bstr_t("6"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl6);
        preparedCommand->Parameters->Append(inputParam);
        //LL 7
        vLl7.vt = VT_I2;
        vLl7.iVal = ll7;
        inputParam = preparedCommand->CreateParameter(_bstr_t("7"),
                                                    adInteger,
                                                    adParamInput,
                                                    sizeof(int),
                                                    vLl7);
        preparedCommand->Parameters->Append(inputParam);

        returnVal.vt = VT_I2;
        returnVal.iVal = 0;
        returnParam = preparedCommand->CreateParameter(_bstr_t("return"),
	                                                   adNumeric,
	                                                   adParamReturnValue,
	                                                   sizeof(_variant_t),
	                                                   returnVal);
	    preparedCommand->Parameters->Append(returnParam);

        resultSet = preparedCommand->Execute(&rowsAffected, NULL, adCmdStoredProc);
        printf("Complete, rows effected: %d", rowsAffected.lVal);
    }

<< moderator edit: added [code][/code] tags >>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.