CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset"); pConn->Open("Provider=sqloledb;Data Source=Server1;"
"Initial Catalog=test1;User Id=sa;Password=sa;",
"", "", adConnectUnspecified);
// Note 1.
pRst->Open(
"userinfo",
_variant_t((IDispatch *) pConn, true),
adOpenStatic,
adLockReadOnly,
adCmdTable);
pRst->MoveLast();
// Note 2.
printf("Last name is '%s %s'\n",
(char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()),
(char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value)); pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset"); pConn->Open("Provider=sqloledb;Data Source=Server1;"
"Initial Catalog=test1;User Id=sa;Password=sa;",
"", "", adConnectUnspecified);
// Note 1.
pRst->Open(
"userinfo",
_variant_t((IDispatch *) pConn, true),
adOpenStatic,
adLockReadOnly,
adCmdTable);
pRst->MoveLast();
// Note 2.
printf("Last name is '%s %s'\n",
(char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()),
(char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value)); pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
解决方案 »
- 关于切分窗口和CFormView的问题!
- 在对话框上调用gif动画的问题,请进来进来看看!
- 怎麽可以設置一個按鈕的背景色和前景色,
- 怎样让程序知道系统里窗口的焦点切换了??求救
- 在消息响应函数中能得到该消息的消息ID吗?
- 如何从HWND得到CWnd*?
- 问一个简单的问题:我将一个*.ppt格式文件里的内容拷到我的*.doc文件里,在*.ppt里的文字有阴影,而*.doc里的文字无阴影,我怎样才能在*.
- sans(sans)请你发一份读硬盘序列号的代码给我好吗?急用!!!200分!!!
- MFC EDITVIEW 标题栏格式
- HWND究竟是个指针还是整形量?
- 月底去深圳求职,有没有深圳的朋友?
- 哈哈,你们现在想知道太阳系某个星球的样子吗?告诉我,我拍摄给你。
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
在文件中void CADO100View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
HRESULT hr;
_bstr_t source("Driver={SQL Server};Server=REDFOX;\
Uid=sa;Pwd=57190;Database=公司");
_bstr_t user("dbo");
_bstr_t pwd("");
try{
hr=m_connection.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
hr=m_connection->Open(source,user,pwd,16);
if(SUCCEEDED(hr))
hr=m_recordset.CreateInstance(_uuidof(Recordset));
if(SUCCEEDED(hr))
m_fConnected=TRUE;
else
m_fConnected=FALSE;
}
catch(_com_error &e){
MessageBox(e.ErrorMessage());
m_fConnected=FALSE;
}
if(!m_fConnected) MessageBox("ADO 数据源初始化失败!");
else m_strSource=(const char *) source;
}
为什么总是连不上?