Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having serious problem calling SP in C++

Status
Not open for further replies.

bloggins02

Programmer
Jul 9, 2000
5
0
0
US
Hi all,

I am using MSVC++ 6.0 with ODBC connecting to SQL Server.

I have allocated two statement handles. The idea is to call
a select statement that returns a number that is used as one of the arguments for the stored procedure, ex:

SQLExecDirect(hGetNum, _T("select number from table where cond1 = 'someval' and cond2 = 'someval2'"), _tcslen(...));

SQLFetch(hGetNum);

SQLFreeStmt(hGetNum, SQL_CLOSE);

then I use the number that it retrieved (from a variable bound to the collumn) as an argument to a stored procedure, say:

SQLExecDirect(hCallSP, _T("{call SomeSP(?)}"), _tcslen(...));

where the variable represented by the "?" has already been bound as a parameter, and the value obtained from the select statement has been copied to the variable.

So let's say the stored procedure doesn't return anything, it just updates a database. Well if I use this code, the select statement gets the right value I need for the stored procedure, and the stored procedure (seems to) execute without errors, but when I manually query the DB it doesn't show that any changes were made. Furthermore, if I take the select stuff out and just hardcode in the parameter for the SP (having obtained it by doing a manual select query from an SQL worksheet application) it works fine.

It only doesn't work if I execute the select statment and then try to do the stored procedure. Note that the query and the stored procedure are both working on the same table.

Does anybody know what could be causing this? Thanks a bunch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top