Calling store procedure using CDatabase/CRecordset 
Author Message
 Calling store procedure using CDatabase/CRecordset

Hi All

How can I call store procedure by using CDatabase/CRecordset?



Mon, 28 Feb 2000 03:00:00 GMT  
 Calling store procedure using CDatabase/CRecordset

Search for "Declaring a Class for a Predefined Query" In the Online Help.

> Hi All

> How can I call store procedure by using CDatabase/CRecordset?

> Thanks

> Ferrong

Tue, 29 Feb 2000 03:00:00 GMT  
 Calling store procedure using CDatabase/CRecordset

There are a couple of different options.  If you want to call a Stored Proc
using a record set class, you can replace the GetDefaultSQL return value
that is generated for you by the wizard with the call to the stored
procedure.  For example.

CString CDBSPTestSet::GetDefaultSQL()
i,'%s',%i,%i,'%s',%i,%i)}", g_spCode, g_spAuthorID, g_spLoginID,
g_spLoginNum, g_spLastName,     g_spFirstName, g_spSignature, g_spSpecialtyID,
g_spGender, g_spDialect, g_spCustomerID, g_spMaxDictLen, g_spTraining,
g_spPINReq, g_spPIN, g_spCollectRptType, g_spCollectPTInfo,
g_spAcousticAdap, g_spPriority, g_spUseRec);

return RequeryString;


...  Later in the code ...
CDBSPTestSet*  MyRecSet;

MyRecSet->Open();  // CRecordset::Open() calls Get Default SQL which
returns the string you provide
                // and when it is executed this calls the stored procedure.

The g_sp variables you see are global vars used to dynamically substitute
parameters that I am sending into the stored procedure.  If you do this,
every time you call Open() on this recordset, it calls the indicated stored
procedure, dbo.Auth_DIES.    

To call it using a CDatabase object, you can do the same thing.  First, you
define a string to pass into "CDatabase.Open(<Your Connection string
here>);" an example connection string is:  "ODBC;DSN=SQLServer", once the
connection is open, you can use "Datebase.ExecuteSQL(<Your SP Call String
here>); an example follows.

// Using CDatabase to call SP.
CDatabase* MyDatabase = new CDatabase;
MyDatabase->Open("ODBC;DSN=SQLSever");  // you need to define your own
MyDatabase->ExecuteSQL("{CALL dbo.MyProcedureName(Var1, Var2)}");
delete MyDatabase;  // when you are done using it.

        I have found that if you are not returning records from the stored
procedure, use a CDatabase object, if you do return records us the
CRecordset object.  If you do both, you can use the CDatabase object within
your CRecordset to call any stored procs that don't return records.


> Hi All

> How can I call store procedure by using CDatabase/CRecordset?

> Thanks

> Ferrong

Sat, 04 Mar 2000 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Calling stored procedure using CDatabase class

2. Stored procedures accessing more than one server in a single CDatabase and CRecordset object

3. CRecordset call stored procedure error

4. Problem calling Stored Procedure from CRecordset

5. Getting the return value of a stored procedure using CRecordset

6. calling Stored procedure using OleDbConnection

7. Calling Stored Procedures Using ADO2.5 in Visual C++ 6

8. Calling Oracle stored procedures using MFC's classes

9. CDatabase::ExecuteSQL(...) does not drop a stored procedure

10. Calling Parameterised Stored Proceedures which returns no records using CRecordset

11. CRecordset and stored procedures with params that default to NULL

12. CRecordset updated via stored procedure


Powered by phpBB® Forum Software