OLE DB and stored procedure

Aug 21, 2011 at 3:02pm
I have code, but return value == 0. Why?
1
2
3
4
5
6
7
8
9
10
ALTER PROCEDURE [dbo].[myproc] 
(
@mykod INT
)
RETURNS INT
AS
BEGIN 
select * from table1 where kod=@mykod
RETURN 99
END

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


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 = &sprocparams;
    Params.cParamSets = 1;
    Params.hAccessor = hAccessor;

	LONG      cRowsAffected;

	IRowset*    pIRowset;


hr = pICommandText->Execute(NULL, IID_IRowset, &Params,&cRowsAffected, (IUnknown**) &pIRowset);
if (FAILED(hr)) AfxMessageBox("Execute Failed");

CString str;
str.Format("%d",sprocparams.lReturnValue);
//return 0 !!!!!!!!!!!!!!!!!!!!!!!!!!
AfxMessageBox(str);	
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

pIRowset->Release();


str.Format("%d",sprocparams.lReturnValue);
//return 0 !!!!!!!!!!!!!!!!!!!!!!!!!!
AfxMessageBox(str);	
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Aug 21, 2011 at 5:54pm
http://www.cplusplus.com/forum/articles/1295/
When asking about code
Don't ask others to debug your broken code without giving a hint what sort of problem they should be searching for. Posting a few hundred lines of code, saying "it doesn't work", will get you ignored. Posting a dozen lines of code, saying "after line 7 I was expecting to see <x>, but <y> occurred instead" is much more likely to get you a response.
Aug 22, 2011 at 4:08am
I marked code where I have error. Look closely at my code!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
hr = pICommandText->Execute(NULL, IID_IRowset, &Params,&cRowsAffected, (IUnknown**) &pIRowset);
if (FAILED(hr)) AfxMessageBox("Execute Failed");

CString str;
str.Format("%d",sprocparams.lReturnValue);
//return 0 !!!!!!!!!!!!!!!!!!!!!!!!!!
AfxMessageBox(str);	
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

pIRowset->Release();


str.Format("%d",sprocparams.lReturnValue);
//return 0 !!!!!!!!!!!!!!!!!!!!!!!!!!
AfxMessageBox(str);	
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 


Return code must be value 99.
Topic archived. No new replies allowed.