高分问题!

mohuifu_2000 2003-04-11 04:07:28
HRESULT hr;
_RecordsetPtr pRstEmployee;
_ConnectionPtr pConnection;

pRstEmployee = NULL;
pConnection = NULL;

try
{
hr = pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = pConnection->Open(strCnn,"","",adConnectUnspecified);
}

}
catch(_com_error e)
{
// _bstr_t sCnn("Driver=SQL Server;SERVER=100note;DATABASE=;UID=;PWD=");
_bstr_t mystr("Driver=SQL Server;Database=;Server=100note;UID=sa;PWD=;");
pConnection->ConnectionString = mystr;//"Driver=SQL
Server;Database=;Server=100note;UID=sa;PWD=;";
pConnection->ConnectionTimeout = 5;
// pConnection->Open(strCnn,"","",adConnectUnspecified);
_bstr_t str("Create Database TestAdo"); //error
pConnection->Execute(str,NULL,NULL);

CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return;
}

以上代码中:
hr = pConnection.CreateInstance("ADODB.Connection");
hr = pConnection->Open(strCnn,"","",adConnectUnspecified);

为什么pConnection后,有的用。有的用-> 难道 pConnection可以同时为对象和指向对象的指针?

...全文
19 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnh_xu 2003-04-11
  • 打赏
  • 举报
回复
在COM规范中,如此这般可称为智能指针
winphoenix 2003-04-11
  • 打赏
  • 举报
回复
在COM规范中,如此这般可称为智能指针

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧