ado问题三:_RecordsetPtr

blt 2004-06-25 05:00:58
_ConnectionPtr pMyConnect = NULL;
HRESULT hr = pMyConnect.CreateInstance( __uuidof( Connection ) );
if( FAILED( hr ) )
{
AfxMessageBox( "pMyConnect.CreateInstance失败" );
return;
}

_bstr_t strConnect = "Provider=OraOLEDB.Oracle;Data Source=db;User Id=aaa;Password=bbb;";
//connecting to the database server now:
try
{
pMyConnect->Open( strConnect, "","" , NULL );
AfxMessageBox( "连接成功" );
}
catch( _com_error &e )
{
::MessageBox(NULL,e.Description(),"警告",MB_OK | MB_ICONWARNING);
return;
}

_RecordsetPtr m_pRecordset;
if( !FAILED( m_pRecordset.CreateInstance( __uuidof( Recordset ) ) ) )
{
AfxMessageBox( "m_pRecordset.CreateInstance失败" );
pMyConnect->Close();
return;
}

try
{
m_pRecordset->Open( _variant_t( "oe_press" ),
_variant_t( ( IDispatch * )pMyConnect, true ),
adOpenKeyset,
adLockOptimistic,
adCmdTable );
AfxMessageBox( "打开表成功" );
}
catch( _com_error &e )
{
AfxMessageBox( "无法打开表" );
}
pMyConnect->Close();

运行时m_pRecordset.CreateInstance失败,请教高人指点。
...全文
78 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
nightfallrove 2004-06-25
  • 打赏
  • 举报
回复
_RecordsetPtr m_pRecordset;
if( FAILED( m_pRecordset.CreateInstance( __uuidof( Recordset ) ) ) )
{
AfxMessageBox( "m_pRecordset.CreateInstance失败" );
pMyConnect->Close();
return;
}
Kudeet 2004-06-25
  • 打赏
  • 举报
回复
你是语句有问题吧!你的对话框在创建成功的时候会跳出来
if( FAILED( m_pRecordset.CreateInstance( __uuidof( Recordset ) ) ) )//感叹号

4,018

社区成员

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

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