MFC通过ADO访问SQL数据库
CoInitialize(NULL); //AfxOleInit();_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command));//实例化一个Command对象pCmd
if (FAILED(pConn.CreateInstance("ADODB.Connection")))
{
AfxMessageBox(L"Create Instance failed!");
return;
}
pConn->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI; Initial Catalog=Component;Data Source=VISIONSKY\\sqlexpress;","","",adModeUnknown);
AfxMessageBox(L"连接成功");
}
catch(_com_error e)
{
AfxMessageBox(L"连接失败" +e.Description());
}
页:
[1]