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

📄 wglrecordset.cpp

📁 Vc源码用ado连接数据库的源程序 简单实用
💻 CPP
字号:
// WglRecordset.cpp: implementation of the WglRecordset class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Wgl.h"
#include "WglRecordset.h"

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

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

WglRecordset::WglRecordset()
{
  
}
WglRecordset::WglRecordset(_ConnectionPtr m_pConn)
{
	m_pRecordset.CreateInstance(__uuidof(Recordset)); 
 	m_pConnection=m_pConn;
	Flag = TRUE;

}
WglRecordset::~WglRecordset()
{
  
}
BOOL  WglRecordset::GetConnection(_ConnectionPtr m_pConn)
{
	m_pRecordset.CreateInstance(__uuidof(Recordset)); //COM接口
	if( Flag == FALSE)
	{
		m_pConnection	= m_pConn;		
		Flag = TRUE;
	}
	return TRUE;
}


BOOL WglRecordset::GetRecordset(CString  strTable)
{
	if( Flag == FALSE) return FALSE;


	try
	{
		m_pRecordset->Open((LPCTSTR)strTable, _variant_t((IDispatch *) m_pConnection,true), adOpenDynamic, adLockOptimistic, adCmdUnknown);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}      
	return TRUE;
}

void WglRecordset::SenddataToList(CListBox * pList)
{
    _variant_t var;
    CString strName, strAge;
   try
	{
		if(!m_pRecordset->BOF)
			m_pRecordset->MoveFirst();
		else
		{
			AfxMessageBox("表内数据为空");
			return;
		}

		// 读入库中各字段并加入列表框中
		while(!m_pRecordset->adoEOF)
		{
			var = m_pRecordset->GetCollect("NAME");
			if(var.vt != VT_NULL)
				strName = (LPCSTR)_bstr_t(var);
			var = m_pRecordset->GetCollect("AGE");
			if(var.vt != VT_NULL)
				strAge = (LPCSTR)_bstr_t(var);

			pList->AddString( strName + " --> "+strAge );
			m_pRecordset->MoveNext();
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}     

}

⌨️ 快捷键说明

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