资源简介
c++ 利用ado操作sql server的封装类,包括增删改查的全部操作

代码片段和文件信息
//
// MODULE: Ado2.cpp
//
// AUTHOR: Carlos Antollini
//
// mailto: cantollini@hotmail.com
//
// Date: 07/02/2003
//
// Version 2.10
//
#include “ado2.h“
#define ChunkSize 100
BOOL CJetEngine::CCompactDatabase(CString strDatabaseSource CString strDatabaseDestination)
{
try
{
::CoInitialize(NULL);
IJetEnginePtr jet(__uuidof(JetEngine));
HRESULT hr = jet->CompactDatabase(_bstr_t(strDatabaseSource.GetBuffer(0)) _bstr_t(strDatabaseDestination.GetBuffer(0)));
::CoUninitialize();
return hr == S_OK;
}
catch(_com_error &e)
{
::CoUninitialize();
return FALSE;
}
}
///////////////////////////////////////////////////////
//
// CADODatabase Class
//
DWORD CADODatabase::GetRecordCount(_RecordsetPtr m_pRs)
{
DWORD numRows = 0;
numRows = m_pRs->GetRecordCount();
if(numRows == -1)
{
if(m_pRs->EndOfFile != VARIANT_TRUE)
m_pRs->MoveFirst();
while(m_pRs->EndOfFile != VARIANT_TRUE)
{
numRows++;
m_pRs->MoveNext();
}
if(numRows > 0)
m_pRs->MoveFirst();
}
return numRows;
}
BOOL CADODatabase::Open(LPCTSTR lpstrConnection LPCTSTR lpstrUserID LPCTSTR lpstrPassword)
{
HRESULT hr = S_OK;
if(IsOpen())
Close();
if(strcmp(lpstrConnection _T(““)) != 0)
m_strConnection = lpstrConnection;
ASSERT(!m_strConnection.IsEmpty());
try
{
if(m_nConnectionTimeout != 0)
m_pConnection->PutConnectionTimeout(m_nConnectionTimeout);
hr = m_pConnection->Open(_bstr_t(m_strConnection) _bstr_t(lpstrUserID) _bstr_t(lpstrPassword) NULL);
return hr == S_OK;
}
catch(_com_error &e)
{
dump_com_error(e);
return FALSE;
}
}
void CADODatabase::dump_com_error(_com_error &e)
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format( “CADODatabase Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n“
e.Error() e.ErrorMessage() (LPCSTR)bstrSource (LPCSTR)bstrDescription);
m_strErrorDescription = (LPCSTR)bstrDescription ;
m_strLastError = _T(“Connection String = “ + GetConnectionString() + ‘\n‘ + ErrorStr);
m_dwLastError = e.Error();
#ifdef _DEBUG
AfxMessageBox(ErrorStr MB_OK | MB_IConerror );
#endif
}
BOOL CADODatabase::IsOpen()
{
if(m_pConnection )
return m_pConnection->GetState() != adStateClosed;
return FALSE;
}
void CADODatabase::Close()
{
if(IsOpen())
m_pConnection->Close();
}
///////////////////////////////////////////////////////
//
// CADORecordset Class
//
CADORecordset::CADORecordset()
{
m_pRecordset = NULL;
m_pCmd = NULL;
m_strQuery = _T(““);
m_strLastError = _T(““);
m_dwLastError = 0;
m_pRecBinding = NULL;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pCmd.CreateInstance(__uuidof(Command));
m_nEditStatus = CADORecordset::dbEditNone;
m_nSearchDirection = CADORecordset::searchForward;
}
CADORecordset::CADORecordset(CADODatabase* p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 46994 2010-07-21 16:54 封装--完\ado2.cpp
文件 17566 2003-08-09 22:21 封装--完\ado2.h
目录 0 2010-08-27 12:19 封装--完
----------- --------- ---------- ----- ----
64560 3
- 上一篇:v4l2 mfc 视频解码
- 下一篇:地铁换乘系统
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- Adobe Acrobat X Pro汉化CIDFont字体包
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- Qt查询SQLite数据库
- C++17 In Detail
- QT SQLite封装
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
评论
共有 条评论