在VC++中如何从数据库中读取数据和向数据库中写入数据

来源:百度知道 编辑:UC知道 时间:2024/05/28 17:40:44
给个简单的示例(程序),要求有注释
我用的是access

#include "stdafx.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ADOConn::ADOConn()
{

}

ADOConn::~ADOConn()
{

}

// 初始化—连接数据库
void ADOConn::OnInitADOConn()
{
// 初始化OLE/COM库环境
::CoInitialize(NULL);

try
{
// 创建Connection对象
m_pConnection.CreateInstance("ADODB.Connection");
// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect = "Provider=MSDASQL.1;Persist Security Info=False;User ID=***;Data Source=***;";
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
// 捕捉异常