Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1640
  • Last Modified:

CDatabase using C++

Hello All,

I am new to using C++ MFC CDatabase class to call a stored procedure.  Can anyone provide a source to learn how to call a stored procedure and return a record set.  I am passing 4 input parameters and return 3 output parameters.

thanks in advance...

regards,

Ken
0
kenhoppe
Asked:
kenhoppe
  • 2
1 Solution
 
jkrCommented:
Take a look at http://www.codeproject.com/database/myrecordset.asp ("Two classes for parameterized SQL statement and stored procedure")
0
 
itsmeandnobodyelseCommented:
You can use the CRecordset class:

  CRecordset rset(pdb);   // pass the CDatabase pointer
  if (!rset.Open(CRecordset::snapshot, "{call OverDueAccts}"))
  {
          // something goes wrong
  }


Regards, Alex
0
 
itsmeandnobodyelseCommented:
You also can use CDatabase::ExecuteSQL.

Here I found the following code sample:
-----------------------------------
Create the following stored procedure in the PUBS Database:


CREATE PROCEDURE get_author_titles @au_id id
AS
BEGIN
SELECT * FROM authors where au_id = @au_id
if @@ROWCOUNT = 0
RAISERROR ('No author found',15,10)
else
SELECT title_id FROM titleauthor WHERE au_id = @au_id
END
Create an MFC AppWizard application with database header support. Create a menu handler.

Paste the following code into the handler:

      CDatabase db;
      db.OpenEx(_T("DSN=Pubs;UID=sa;PWD=;"));
      try {
            db.ExecuteSQL(_T("EXEC get_author_titles '998-72-3567'"));
            db.ExecuteSQL(_T("EXEC get_author_titles '998-72-3568'"));
      }
      catch (CDBException* pEx)
      {
            TCHAR buff[80];
            pEx->GetErrorMessage(buff,80);
            AfxMessageBox(buff);
            pEx->Delete();
      }

------------- end sample ---------------------------

The sample is how to handle an exception between two calls of a stored procedure but it may help nevrtheless.

Regards, Alex
0

Featured Post

Independent Software Vendors: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now