4,011
社区成员
发帖
与我相关
我的任务
分享
try
{
HRESULT hr =pConn.CreateInstance("ADODB.Connection");
if (FAILED(hr))
{
AfxMessageBox("初始化失败!");
}
CString str;
str = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data ource =192.168.1.16";
_bstr_t strConnect =str;
pConn->Open(strConnect,"","",adModeUnknown);
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
}
HRESULT hr = pCommand.CreateInstance(__uuidof(Command));
hr = pRecordset.CreateInstance(__uuidof(Recordset));
pCommand->ActiveConnection = pConn;
pCommand->CommandText = "select * from TestTab ";
if (FAILED(hr))
{
pRecordset = NULL;
AfxMessageBox("can't create an instance of Recordset");
}
try
{
pRecordset=pCommand->Execute(NULL,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}