惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - dgz

c/c++之预处理 派生类的拷贝构造函数 虚函数和接口的差别 CALLBACK 函数 vc中LNK2001错误以及解决方案(转载) C++类对象的拷贝构造函数(转载) C++的static关键字(转载) 指针常量,常量指针 static 和 const的解释(转载) 数据类型转换:static_cast,const_cast等用法(转载) static用法小结(转载) Windows多线程多任务设计初步 最简单的完成端口代码 SOCKET模型之重叠I/O篇(转贴) WindowsSockets2.0:使用完成端口高性能,可扩展性Winsock服务程序(转载) CListCtrl 使用技巧(转载) C++字符串—— Win32 字符编码 com+调试 如何在VC++ 编写的组件中使用 ADO
com+返回recordset
dgz · 2006-05-20 · via 博客园 - dgz

HRESULT   GetByID([in]   BSTR   bstrUnitID   ,   [out,retval]   LPDISPATCH   *ppRecordset);  
   
  ----------------------------------------------------------  
  Implementation:  
   
  STDMETHODIMP   CChargeC::GetByID(BSTR   bstrUnitID,   LPDISPATCH   *ppRecordset)  
  {  
  AFX_MANAGE_STATE(AfxGetStaticModuleState())  
   
  //   TODO:   Add   your   implementation   code   here  
   
  if(ppRecordset   ==   NULL)  
  return   E_INVALIDARG;  
   
  *ppRecordset   =   NULL;  
   
  HRESULT   hr   =   S_OK;  
   
  try{  
  _ConnectionPtr   pAdoConnection;  
  _RecordsetPtr   pAdoRecordset;  
   
  _bstr_t   bstrSQL;  
  _variant_t   vntRecordsAffected;  
  basic_stringstream   <   wchar_t   >   bssSQL;  
   
  pAdoConnection.CreateInstance(__uuidof(Connection));  
   
  pAdoConnection->CursorLocation   =   adUseClient;  
  pAdoConnection->Open(   m_bstrConnectionString   ,   (BSTR)NULL   ,   (BSTR)NULL   ,   -1);  
   
  bssSQL   <<   L"SELECT   *   FROM   表_收费   WHERE   单元号   =   '"   <<   bstrUnitID   <<   L"'"   <<   ends;  
  bstrSQL   =   bssSQL.str().c_str();  
   
  TRACE0(_T("In   db_ChargeC.ChargeC!CChargeC::GetByID\n"));  
  TRACE1(_T("SQL   =   %s\n\n")   ,   (LPCTSTR)bstrSQL);  
   
  pAdoRecordset   =   pAdoConnection->Execute(bstrSQL   ,   &vntRecordsAffected   ,   adCmdText);  
  pAdoRecordset->PutRefActiveConnection(   NULL   );  
  pAdoRecordset->AddRef();  
  pAdoRecordset->QueryInterface(IID_IDispatch   ,   (void   **)   ppRecordset);  
   
  if(m_spObjectContext   !=   NULL)  
  m_spObjectContext->SetComplete();  
  }  
  catch(_com_error   &e)  
  {  
  hr   =   e.Error();  
  if(m_spObjectContext   !=   NULL)  
  m_spObjectContext->SetAbort();  
   
  TRACE1(_T("\nError   occured   in   db_ChargeC.ChargeC!CChargeC::GetByID\nError   Number   :   %d\n")   ,   hr);  
  TRACE3(_T("Source   :   %s\nDescription   :   %s\nErrorMessage   :   %s\n")   ,  
  (LPCTSTR)   e.Source()   ,   (LPCTSTR)   e.Description()   ,   (LPCTSTR)   e.ErrorMessage());  
   
  CString   str   =   (LPCTSTR)   e.Description();  
  if(str.GetLength()<1)  
  str   =   e.ErrorMessage();  
   
  if(str.GetLength()<1)  
  str   =   "Unknown";  
   
  AtlReportError(CLSID_ChargeC   ,   (LPCTSTR)str   ,   IID_IChargeC   ,   hr);  
  }  
   
  return   hr;  
  }  

一个增加用户的框架
// Users.cpp : Implementation of CUsers
#include "stdafx.h"
#include "HisCommVc.h"
#include "Users.h"

#include <mtx.h>

#include <sstream>

using namespace std;
/////////////////////////////////////////////////////////////////////////////
// CUsers

STDMETHODIMP CUsers::InterfaceSupportsErrorInfo(REFIID riid)
{
 static const IID* arr[] = 
 {
  &IID_IUsers
 };
 for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
 {
  if (InlineIsEqualGUID(*arr[i],riid))
   return S_OK;
 }
 return S_FALSE;
}

////////////////////////////////////////////////////////////////////
//接口名称: Add 往用户字典表中增加一条记录
//Input: loginID  数据库登录名
//   userName 姓名
//   passWord 密码
//   userDept 
//   casherNo 
//   createDate 日期
//Output: 无
///////////////////////////////////////////////////////////////////
STDMETHODIMP CUsers::Add(BSTR loginId, BSTR userName, BSTR passWord,BSTR userDept, BSTR cashNo, DATE createDate)
{
 // TODO: Add your implementation code here
 _ConnectionPtr padoConnection = NULL;
  CComPtr<IObjectContext> pObjCtx = NULL;
 HRESULT hr = S_OK;
 _bstr_t strSQLStmt;

 try
 {
  //创建MTS上下文环境
   hr = GetObjectContext(&pObjCtx);
 
   // String I/O stream to write SQL statement
   basic_stringstream<wchar_t> strSQLStatement;
  
  //创建SQL语句
  strSQLStatement<<L"insert into hiscomm.dbo.users("
   <<L"login_id,user_name,password,user_dept,casher_no,create_date) values('"
   << static_cast<wchar_t *>(FixSQLString(loginId)) << L"','"
   << static_cast<wchar_t *>(FixSQLString(userName)) << L"','"
   << static_cast<wchar_t *>(FixSQLString(passWord)) << L"','"
   << static_cast<wchar_t *>(FixSQLString(userDept)) << L"','"
   << static_cast<wchar_t *>(FixSQLString(cashNo)) << L"','"
   << static_cast<wchar_t *>(FixSQLString(createDate)) << L"')";
     
  //转换成bstr_t
   strSQLStmt = strSQLStatement.str().c_str();
       //连接数据库
  hr = OpenConnection((LPDISPATCH*)&padoConnection);
       //执行SQL语句
  padoConnection->Execute(strSQLStmt,NULL,adCmdText);
  
   if (pObjCtx)
    pObjCtx->SetComplete();
  if (padoConnection)
   padoConnection->Close();
  }
  //返回错误信息
  catch(_com_error &e)
  {

  BSTR err=e.Description ();
 
   if (pObjCtx)
    pObjCtx->SetAbort();
   if (padoConnection)
   {
    padoConnection->Close();
   }

  hr=e.Error();
  return Error(err,NULL,NULL,IID_IUsers,hr);
  }

 return S_OK;
}