大家会VC用ADO连接oracle的请帮忙指点,谢谢!
VC用ADO连接oracle的方法,请大家举个例子,最好能实现增,删,改,查的,先谢谢大家了!!!有追分...
VC用ADO连接oracle的方法,请大家举个例子,最好能实现增,删,改,查的,先谢谢大家了!!!有追分
展开
2个回答
展开全部
这个例子里用户名和密码都是pzone 数据库名是zp
改成你想要的就行了
import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
// 初始化COM,创建ADO连接等操作
AfxOleInit();
连接:
m_pConnection.CreateInstance(__uuidof(Connection));
try //建立数据库连接
{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=OraOLEDB.Oracle.1;Password=pzone;User ID=pzone;Data Source=zp;Persist Security Info=True","","",adModeUnknown);
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("数据库连接失败!\r\n错误信息:%s", e.ErrorMessage());
AfxMessageBox(errormessage);
//return FALSE;
}
查
_bstr_t sql="select name from booktype";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(sql, m_pConnection->GetConnectionString(),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)//判断表内数据是否为空
m_pRecordset->MoveFirst();
else{
AfxMessageBox("BookType表内数据为空");
return;
}
while(!m_pRecordset->adoEOF){
CString item=m_pRecordset->GetCollect("name");
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
增加:
_bstr_t sql="insert into tablename values (".....;
m_pConnection->Execute(sql,NULL,adCmdText);
删除
_bstr_t sql="delete from tablename where ...";
m_pConnection->Execute(sql,NULL,adCmdText);
改
_bstr_t sql="update tablename set xx=...";
m_pConnection->Execute(sql,NULL,adCmdText);
改成你想要的就行了
import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
// 初始化COM,创建ADO连接等操作
AfxOleInit();
连接:
m_pConnection.CreateInstance(__uuidof(Connection));
try //建立数据库连接
{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=OraOLEDB.Oracle.1;Password=pzone;User ID=pzone;Data Source=zp;Persist Security Info=True","","",adModeUnknown);
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("数据库连接失败!\r\n错误信息:%s", e.ErrorMessage());
AfxMessageBox(errormessage);
//return FALSE;
}
查
_bstr_t sql="select name from booktype";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(sql, m_pConnection->GetConnectionString(),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)//判断表内数据是否为空
m_pRecordset->MoveFirst();
else{
AfxMessageBox("BookType表内数据为空");
return;
}
while(!m_pRecordset->adoEOF){
CString item=m_pRecordset->GetCollect("name");
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
增加:
_bstr_t sql="insert into tablename values (".....;
m_pConnection->Execute(sql,NULL,adCmdText);
删除
_bstr_t sql="delete from tablename where ...";
m_pConnection->Execute(sql,NULL,adCmdText);
改
_bstr_t sql="update tablename set xx=...";
m_pConnection->Execute(sql,NULL,adCmdText);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询