打印本文 打印本文 关闭窗口 关闭窗口
用Delphi的思想初步构建C++的ADO对象
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3708  更新时间:2009/4/23 10:43:17  文章录入:mintao  责任编辑:mintao
              return TRUE;

       else

              return FALSE;

}

 

 

//CAdoCommand

CAdoCommand::CAdoCommand()

{

       m_AdoConnection = NULL;

       CommandText = adCmdText;

       // 创建一个命令对象实例

       try {

              HRESULT hr = m_ptrComm.CreateInstance(__uuidof(Command));

              if (FAILED(hr)) {

                     CString errormessage("创建实例失败!");

                     AfxMessageBox(errormessage);

              }

       }

       catch(_com_error & error) {

              CString errormessage;

              errormessage.Format("创建实例失败!\r\n错误信息:%s", error.ErrorMessage());

              AfxMessageBox(errormessage);

       }    

}

      

CAdoCommand::~CAdoCommand()

{

       m_ptrComm = NULL;

}

 

void CAdoCommand::Execute()

{

       if ((m_AdoConnection == NULL) || (m_AdoConnection->Connected == FALSE))

              return;

      

       m_ptrComm->ActiveConnection = m_AdoConnection->m_ptrConn;

       m_ptrComm->CommandType = CommandType;

       m_ptrComm->CommandText = CommandText.c_str();

       try {

              m_ptrComm->Execute(NULL,NULL,adCmdUnknown);

       }

       catch(_com_error & error) {

              CString errormessage;

              errormessage.Format("查询数据库失败!\r\n错误信息:%s", error.ErrorMessage());

              AfxMessageBox(errormessage);

       }

}

 

CAdoCommand::operator _CommandPtr()

{

       return m_ptrComm;

}

 

 

再来看一下我的简单的界面以及客户代码吧:

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口