高分问题!
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可以同时为对象和指向对象的指针?