Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Call a stored procedure without using CRecordset...

Posted on 2002-04-08
7
Medium Priority
?
340 Views
Last Modified: 2013-11-20
Hello, everyone.

Could anyone show me how to call a stored procedure which returns a value in VC++? (WITHOUT using CRecordeset)

I searched and got a few answers here but those were not what I wanted. Let me explain what I need for my project.
It's a multi-threaded program, and each thread must call the stored procedure continually while running. The stored procedure is like the bottom:

CREATE PROCEDURE GetMyNum
@In_MyStr varchar(15),
@Out_Result smallint OUTPUT
AS

SET @In_MyStr = RTRIM(LTRIM(@In_MyStr))
SET @Out_Result = 0

SELECT @Out_Result = theNum
FROM NumTable
WHERE theStr = @In_MyStr


I am from VB so it's very easy to do this with a Command object without using any recordset object. When I looked at a sample VC++ code somewhere and I was just lost.

There are several ways to accomplish the logic above. The reason why I chose this scenario is that I thought it might be better for performance (speed mostly).
Let me elaborate my logic a little bit.
My thought is that:

- Create a global connection object when the program starts.

- Create threads and they are going to use the connection object for its Command object's ActiveConnection.

- When I need a number from database, I call the stored procedure through the command object and get the value from the command object without even bothering with a CRecordset object.
 

Thank you in advance for any input.
Happy programming.
0
Comment
Question by:alexzen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6989421
Without using a CRecordset, you would need to use PRO*C.
If you want to use a CRecordset, there are a few techniques.
0
 

Author Comment

by:alexzen
ID: 6992000
Thank you for your comment, Triskelion.

Could you elaborate what is PRO*C??

Thanks
0
 
LVL 6

Accepted Solution

by:
Triskelion earned 280 total points
ID: 6992103
ORACLE ONLY.

PRO*C is an ORACLE modification to the C language.
It allows the developer to create blocks of SQL code inside of a C module.  The code is run through a pre-compiler that converts the SQL commands into C and the ORACLE OCI (Oracle Call Interface) commands.

Some people would rather use Pro*C than ODBC for code to be used only with Oracle.

http://www.altavista.com/sites/search/res_text?sc=on&hl=on&avkw=tgz&q=%22pro+c%22+AND+%22oracle+stored+procedures%22&kl=XX
0
 

Author Comment

by:alexzen
ID: 6992254
Thanks, Triskelion.

Alas, we are a Microsoft Shop.. so I'm using MS SQL server.

Thank you anyway.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 7030399
You can call CDatabase::ExecuteSQL(), but AFAIK, it's only good for stored procedures that do not have result sets.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question