Solved

MFC, Exec Stored Procedure - SQL DB

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 42
not able to insert into temp table 68 169
only14 challenge 19 81
ShiftLeft challenge 21 86
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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