Oracle 访问 access 表
发布网友
发布时间:2022-04-14 03:29
我来回答
共4个回答
热心网友
时间:2022-04-14 04:58
没有办法,oracle是不能直接和access相连的,它能和sqlserver、sybase、infomix等数据库相连,再一个就是在sqlserver里边是可以连access的
热心网友
时间:2022-04-14 06:16
建议导入sqlserver中
热心网友
时间:2022-04-14 07:51
有办法,用VC++直接编程,在Pl/sql developer加个程序快捷方式
1.提取单条记录
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; //*.mdb
//_bstr_t varSource="Data Source=127.0.0.1;Initial Catalog=db2;User Id=;Password=;"
_ConnectionPtr m_pConnection(_uuidof(Connection));
m_pConnection->Open(varSource,"","",adModeUnknow);
_RecordsetPtr m_pSet(_uuidof(Recordset));
try {
m_pSet->Open(%%1,m_pConnection.GetInterfacePtr()
adOpenDynamic,adLockPessimistic,adCmdText);
}
catch(_com_error *e){
{
AfxMessageBox(e->ErrorMessage());
return;
}
_variant_t var;
CString %%2="";
long fldc=m_pSet->GetFields()->GetCount();
long i=0;
try {
m_pSet->MoveFirst();
if(!m_pSet->adoEOF)
{
for(i=0;i<fldc;i++)
{
var=m_pSet->GetCollect((long)i);
var.ChangeType(VT_BSTR);
%%2+=var.bstrVal;
%%2+=" ";
}
//m_pSet->MoveNext();
}
}
catch(_com_error *e){
AfxMessageBox(e->ErrorMessage());
delete e;
}
//m_pSet->MoveFirst();
CoUninitialize();
3.显示表格
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; //*.mdb
//_bstr_t varSource="Data Source=127.0.0.1;Initial Catalog=db2;User Id=;Password=;"
_ConnectionPtr m_pConnection(_uuidof(Connection));
m_pConnection->Open(varSource,"","",adModeUnknown);
//打开属性为默认(adModeRead(只读),adModeWrite(可写),adModeReadWrite(可读写)等)
_RecordsetPtr m_pSet(_uuidof(Recordset));
try {
HRESULT hr=m_pSet->Open(%%1,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
}
catch(_com_error *e){
AfxMessageBox(e->ErrorMessage());
}
if(SUCCESSED(hr))
{
//表打开成功
}
FieldsPtr p_fields=m_pSet->Fields;
FieldPtr p_field;
_variant_t var_index;
LPCSTR field_name;
int index=0;
_bstr_t bstr_field_name;
int countfields=p_fields->GetCount();
CString *Column=new CString[countfields];
CListCtrl *pList=(CListCtrl*)GetDlgItem(%%1);//IDC_LIST_TABLEDATA
VERIFY(pList);
pList->DeleteAllItems();
for(index=0;index<countfields;index++)
{
var_index.vt=VT_I4;
var_index.IVal=index;
p_field=p_fields->Item[var_index];
bstr_field_name=p_field->GetName();
field_name=(LPCSTR)bstr_field_name;
Column[index]=field_name;
int ColumnWidth=Column[index].GetLength()*15;
pList->InsertColumn(index,field_name,LVCFMT_CENTER,ColumnWidth);
}
int i=0;
_bstr_t vCol;
//pList->SetTextBkColor(RGB(122,200,122));
//pList->SetTextColor(RGB(0,0,200));
while(!m_pSet->adoEOF)
{
pList->Insert(i,atoi(i));
for(int j=0;j<countfields;j++)
{
vCol=m_pSet->GetCollect((long)j);
pList->SetItemText(i,j,vCol);
}
m_pSet->MoveNext();
i++;
}
CoUninitialize();
5.数值范围查询
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
try
{
//创建连接对象实例
m_pConnection.CreateInstance("ADODB.Connection");
//设置连接字符串
CString strConnect="DRIVER={Microsoft Access Driver (*.mdb)};\
uid=;pwd=;DBQ=%%0;"; //*.mdb
//使用Open方法连接数据库
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
try {
int min = %%1;
int max = %%2;
CString sql;
sql.Format("select count(*) as pro_count from ProPrice where price between %d and %d",min,max);
HRESULT hr=m_pSet->Open(sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
}
catch(_com_error *e){
AfxMessageBox(e->ErrorMessage());
}
if(SUCCESSED(hr))
{
//表打开成功
}
FieldsPtr p_fields=m_pSet->Fields;
FieldPtr p_field;
_variant_t var_index;
LPCSTR field_name;
int index=0;
_bstr_t bstr_field_name;
int countfields=p_fields->GetCount();
CString *Column=new CString[countfields];
CListCtrl *pList=(CListCtrl*)GetDlgItem(%%1);//IDC_LIST_TABLEDATA
VERIFY(pList);
pList->DeleteAllItems();
for(index=0;index<countfields;index++)
{
var_index.vt=VT_I4;
var_index.IVal=index;
p_field=p_fields->Item[var_index];
bstr_field_name=p_field->GetName();
field_name=(LPCSTR)bstr_field_name;
Column[index]=field_name;
int ColumnWidth=Column[index].GetLength()*15;
pList->InsertColumn(index,field_name,LVCFMT_CENTER,ColumnWidth);
}
6.关闭时断开连接
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
::ExitInstance()
{
if (adStateOpen == m_pConnection->State)
m_pConnection->Close();
m_pConnection.Release();
if(adStateOpen == m_pSet->State)
m_pSet->Close();
m_pSet.Release();
return CWinApp::ExitInstance();
}
7.执行命令
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
if(m_pConnection==NULL) return;
_variant RecordAffected;
try
{
m_pConnection->Execute((_bstr_t)%%1,&RecordAffected,adCmdText);
}
catch(_com_error ce)
{
//执行SQL失败
}
15.access数据库
/*
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
*/
try
{
//创建连接对象实例
m_pConnection.CreateInstance("ADODB.Connection");
//设置连接字符串
CString strConnect="DRIVER={Microsoft Access Driver (*.mdb)};\
uid=;pwd=;DBQ=shujuku.mdb;";
//使用Open方法连接数据库
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
void CConnectDlg::ExitConnect()
{
//关闭记录集和连接
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
}
热心网友
时间:2022-04-14 09:42
用什么来着,用什么来着…………