Click here to Skip to main content
15,886,705 members
Articles / Database Development / SQL Server

Generic Database Class Using ADO to Execute Stored Procedures

Rate me:
Please Sign up or sign in to vote.
3.50/5 (7 votes)
3 May 2001 93.8K   4.1K   37  
Use this class to separate all database calls hidden to the callers. Nobody has to take care of how database retrieval is going on!
// Sample.cpp : Implementation of CSample
#include "stdafx.h"
#include "DBTier.h"
#include "Sample.h"
#include "DatabaseServer.h"
/////////////////////////////////////////////////////////////////////////////
// CSample

HRESULT CSample::Activate()
{
	HRESULT hr = GetObjectContext(&m_spObjectContext);
	if (SUCCEEDED(hr))
		return S_OK;
	return hr;
} 

BOOL CSample::CanBePooled()
{
	return TRUE;
} 

void CSample::Deactivate()
{
	m_spObjectContext.Release();
} 


STDMETHODIMP CSample::SampleCall(BSTR bstrCourseName, long *lCourseID)
{
	HRESULT hresult;
	VARIANT var;
    SAFEARRAY * psa;
     
    SAFEARRAYBOUND rgsabound[1];
    rgsabound[0].lLbound = 0;
    rgsabound[0].cElements = 1;
    psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
	
	VARIANT vtParamValue ;
	long iIndex[1] ;
	for(long lIndex=0 ; lIndex < 1 ; lIndex ++)
	{
		iIndex[0] = lIndex ;
		vtParamValue.vt = VT_BSTR ;
		vtParamValue.bstrVal = bstrCourseName;
		SafeArrayPutElement(psa, iIndex, &vtParamValue);
	}
	CDatabaseServer objDB ;   
	*lCourseID = objDB.setExecStoredProcedure("sp_InsertCourse",psa);	

	return S_OK;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Team Leader
United Kingdom United Kingdom
.Over nine years work experience in different area of Software Engineering especially developing solutions in Visual C++, Visual Basic 6.0 and C# with multi tier architecture.
.Proficient in object-oriented analysis, design and programming especially in distributed client/Server environments.
.Extensive experience in WEB based software engineering using ASP.NET/ASP.
.Vast experience in designing/developing/implementing complex business applications in banking domain.
.Good work experience in Database programming using stored procedures, triggers and generating complex queries using Oracle and SQL Server 2005.

Comments and Discussions