求一个Oracle完整例子—包括连接,记录的读增删改

ytdmm 2004-05-08 03:10:38
rt
用ADO连接Oracle数据库,进行一些基本操作(读取,增加,删除,修改)

3q very much!
...全文
72 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
voljin 2004-05-11
void CDataOperDlg::OnAdd()
{
::CoInitialize(NULL); //初始化OLE/COM库环境
m_pConnection.CreateInstance(_uuidof(Connection)); //初始化Connection指针
m_pRecordset.CreateInstance(_uuidof(Recordset));//初始化Recordset指针

try
{
m_pConnection->Open("Data source = myoraclelink; uid=system; pwd=system;","","",adModeUnknown); //连接叫作ADOTest的ODBC数据源
CString strSql="select * from student";
BSTR bstrSQL = strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
m_pRecordset->AddNew();///添加新记录
m_pRecordset->PutCollect("sno",_variant_t("9"));
m_pRecordset->PutCollect("name",_variant_t("叶利钦"));
m_pRecordset->Update();
m_pRecordset->Close();
MessageBox("add ok");
}
catch (_com_error e)//异常处理
{
AfxMessageBox(e.ErrorMessage());
}
}

void CDataOperDlg::OnDelete()
{
::CoInitialize(NULL); //初始化OLE/COM库环境
m_pConnection.CreateInstance(_uuidof(Connection)); //初始化Connection指针
m_pRecordset.CreateInstance(_uuidof(Recordset));//初始化Recordset指针

try
{
m_pConnection->Open("Data source = myoraclelink; uid=system; pwd=system;","","",adModeUnknown); //连接叫作ADOTest的ODBC数据源
CString strSql="select * from student where sno=9";
BSTR bstrSQL = strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
m_pRecordset->Delete(adAffectCurrent);
m_pRecordset->Update();
m_pRecordset->Close();
m_pConnection->Close();
MessageBox("del ok");
}
catch (_com_error e)//异常处理
{
AfxMessageBox(e.ErrorMessage());
}

}

void CDataOperDlg::OnModify()
{
::CoInitialize(NULL); //初始化OLE/COM库环境
m_pConnection.CreateInstance(_uuidof(Connection)); //初始化Connection指针
m_pRecordset.CreateInstance(_uuidof(Recordset));//初始化Recordset指针

try
{
m_pConnection->Open("Data source = myoraclelink; uid=system; pwd=system;","","",adModeUnknown); //连接叫作ADOTest的ODBC数据源
CString strSql="select * from student where sno=1";
BSTR bstrSQL = strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
m_pRecordset->PutCollect("name",_variant_t("voljin"));
m_pRecordset->Update();
m_pRecordset->Close();
m_pConnection->Close();
MessageBox("mod ok");
}
catch (_com_error e)//异常处理
{
AfxMessageBox(e.ErrorMessage());
}

}
  • 打赏
  • 举报
回复
相关推荐
发帖
数据库
加入

3957

社区成员

VC/MFC 数据库
申请成为版主
帖子事件
创建了帖子
2004-05-08 03:10
社区公告
暂无公告