Solved

MFC, Exec Stored Procedure - SQL DB

Posted on 1998-11-30
5
948 Views
Last Modified: 2013-11-20
Hi All,
I am trying to read info from SQL server DB using the stored procedures. I have created a class derived from CRecordset using MFC, opened it using Open fn. Here is the code,

CString csSql = "exec StoredProcedureName" ;

CDatabase dbMyDB ;

dbMyDB.OpenEx("DSN=DSNName;UID=UserId;PWD=Password") ;

CMyRecordSet cMyRSet(&dbMyDB) ;

cMyRSet.open(CRecordset::snapshot, csSql) ;

Navigate the result set....

I am getting the RunTime error(not the compile time error).
"Incorrect Syntax near the keyword exec"
Do you have any idea? Whats wrong?


0
Comment
Question by:svdam
  • 3
5 Comments
 
LVL 1

Accepted Solution

by:
Bridge earned 20 total points
ID: 1325546
use CALL instead of EXEC
0
 

Author Comment

by:svdam
ID: 1325547
I tried with CALL but I got the error "Invalid object Name CALL"
I would appreciate if you can suggest me some more solutions/methods.


Thanks with regards
dam
0
 
LVL 1

Expert Comment

by:guruprasad031298
ID: 1325548
Try this

CString csSql = "{CALL StoredProcedureName}" ;

Should work fine
0
 

Author Comment

by:svdam
ID: 1325549
Thanks Bridge's and GuruPrasad.  I solved the problem before I see the answer(guruprasad). Anyway Thanks a lot.
csSQL = "{ call SPName } ;
worked fine.

Thank you
Dam



0
 

Author Comment

by:svdam
ID: 1325550
Thanks Bridge's and GuruPrasad.  I solved the problem before I see the answer(guruprasad). Anyway Thanks a lot.
csSQL = "{ call SPName } ;
worked fine.

Thank you
Dam



0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 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