⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createdatabasex.cpp

📁 visual c++ 很全的ado的sample
💻 CPP
字号:
#import "c:\Program Files\Common Files\system\ado\msadox.dll" no_namespace
#import "c:\Program Files\Common Files\system\ado\msado15.dll"

#define TESTHR(x) if FAILED(x) _com_issue_error(hr);

#include "iostream.h"
#include "stdio.h"
#include "conio.h"

//Function declarations
void CreateDatabaseX(void);

//------------------------------------------------------------													//
//Main Function									
//Purpose:  Test Driver
//------------------------------------------------------------													//
void main()
{
	HRESULT hr = S_OK;

	hr = ::CoInitialize(NULL);
	if(SUCCEEDED(hr))
	{
		CreateDatabaseX();

		//Wait here for the user to see the output
		printf("Press any key to continue...");
		getch();
		
		::CoUninitialize();
	}
}

//------------------------------------------------------------													//
//CreateDatabaseX								
//Purpose:  create a new Jet database with the Create method
//------------------------------------------------------------													//
void CreateDatabaseX()
{	
	HRESULT hr = S_OK;

	// Define ADOX object pointers.
    // Initialize pointers on define.
    // These are in the ADOX::  namespace.
	
	_CatalogPtr m_pCatalog = NULL;

	
	//Set ActiveConnection of Catalog to this string
	_bstr_t strcnn("Provider=Microsoft.JET.OLEDB.4.0;"
				"Data source = c:\\new.mdb");
	try
	{
		TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (Catalog)));
		m_pCatalog->Create(strcnn);

	}	

	catch(_com_error &e)
	{
		// Notify the user of errors if any.
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		  
		printf("\n\tSource :  %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);

	}

	catch(...)
	{
		cout << "Error occured in include files...."<< endl;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -