Click here to Skip to main content
15,883,875 members
Articles / Desktop Programming / MFC

A set of ADO classes - version 2.20

Rate me:
Please Sign up or sign in to vote.
4.93/5 (270 votes)
6 Sep 2005Ms-PL27 min read 9.2M   45.2K   741  
Simple database access using an ADO class.
//
// MODULE: oledb2.cpp
//
// AUTHOR: Carlos Antollini <cantollini@hotmail.com>
//
// Copyright (c) 2001-2004. All Rights Reserved.
//
// Date: August 08, 2004
//
// Version 1.01
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name and all copyright 
// notices remains intact. 
//
// An email letting me know how you are using it would be nice as well. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
//
//////////////////////////////////////////////////////////////////////

#include "oledb2.h"

COLEDBDataLink::COLEDBDataLink()
{
	m_pDataLink = NULL;
}

COLEDBDataLink::~COLEDBDataLink()
{
	m_pDataLink = NULL;
}

CString COLEDBDataLink::New(HWND hWnd /*= NULL*/)
{
	m_pDataLink = NULL;
	m_pDataLink.CreateInstance(__uuidof(DataLinks));
	try
	{
		if(hWnd = NULL) m_pDataLink->PuthWnd(reinterpret_cast<long>(hWnd));
		IDispatchPtr pDisp = m_pDataLink->PromptNew();
		
		_ConnectionPtr conn = pDisp;

		CString strReturn = conn->GetConnectionString().copy();

		m_pDataLink.Release();
		m_pDataLink = NULL;
		return strReturn;
	}
	catch(_com_error &e)
	{
		throw COLEDBException(e.WCode(), e.Description());
	}
}

void COLEDBDataLink::Edit(LPCSTR lpstrConnectionString, HWND hWnd)
{
	BOOL bRet;
	m_pDataLink = NULL;
	IDispatch* pDispatch = NULL;
	_ConnectionPtr pAdoConnection;

	m_pDataLink.CreateInstance(__uuidof(DataLinks));
	pAdoConnection.CreateInstance(__uuidof(ADODB::Connection));
	
	try
	{
		m_pDataLink->PuthWnd(reinterpret_cast<long>(hWnd));
		pAdoConnection->PutConnectionString(_bstr_t(lpstrConnectionString));
		pAdoConnection.QueryInterface(IID_IDispatch, (LPVOID*)&pDispatch);

		bRet = m_pDataLink->PromptEdit(&pDispatch) == VARIANT_TRUE;

		m_pDataLink.Release();
		pAdoConnection.Release();
	}
	catch(_com_error &e)
	{
		throw COLEDBException(e.WCode(), e.Description());
	}
}

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.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Citigroup
Argentina Argentina
Carlos Antollini is a software engineer working on Object Oriented, Visual C++, MFC, COM, ATL, ADO, Internet technologies and Business Intelligence.
Carlos is originally from Argentina, he was living for several years in Fort Lauderdale, Florida, working for Citibank. Then he started his own business.
Carlos is the creator of <a href="http://www.piFive.com">piFive</a>[<a target="_blank" title="piFive" href="http://www.piFive.com">^</a>], a family of BI Analytic Platform software, that it deals next to, <a href="http://www.latinsys.com">latinsys</a>[<a target="_blank" title="latinsys" href="http://www.latinsys.com">^</a>], his partner in businesses...
Currently he is sharing his passion for project management and BI at Citigroup.

Comments and Discussions