Solved

MFC, Exec Stored Procedure - SQL DB

Posted on 1998-11-30
5
943 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now