VC連線Oracle資料庫之ODBC及ADO

2021-05-27 15:20:47 字數 2867 閱讀 8703

一.odbc連oracle: 

str.format( "driver=;server=oracleserver.world;uid=username;pwd=asdasd; ")

二.ado連線oracle:

2.要使用net configuration assistant配置好偵聽及相關環境

**

首先,在 stdafx.h 中加入以下**,匯入ado庫

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("eof", "adoeof")

其次,要確保有 ::coinitialize(null)的呼叫,以初始化com.

//類定義

class cdbop  

;

//類實現

cdbop::cdbop():m_bconnectsuccess(false)

cdbop::~cdbop()

//開啟連線(資料庫型別,主機名,資料庫名,登陸名,密碼)

//資料庫型別: 0 為sql server, 1為 oracle

bool cdbop::openconnect(int dbtype,

cstring hostname,

cstring dbname,

cstring username,

cstring password)

else if (dbtype =1) //oracle

if (strconn.isempty())

closeconnect();

m_strconnstring =strconn;

return reconnect();

}//再次連線

bool cdbop::reconnect()

catch(_com_error e)

return m_bconnectsuccess;

}//關閉鏈結

bool cdbop::closeconnect()

return true;

}//取得錯誤資訊

cstring cdbop::geterrormsg()

bool cdbop::getitemdata(cstring itemid, float &price, cstring &descript)

#endif

assert(pcommand != null);

try

//輸入引數 itemid

_parameterptr pparamitemid;

pparamitemid.createinstance("adodb.parameter");

pparamitemid->name="itemid"; //所用儲存過程引數名稱

pparamitemid->type=adchar; //引數型別

pparamitemid->size=10; //引數大小

pparamitemid->direction=adparaminput; //表明是輸入引數

pparamitemid->value=_variant_t(itemid);

//輸出引數 price

_parameterptr pparamprice;

pparamprice.createinstance("adodb.parameter");

pparamprice->name="price"; //引數名稱

pparamprice->type=adnumeric; //引數型別

pparamprice->size=9; //引數大小

pparamprice->precision =9;

pparamprice->numericscale =2;

pparamprice->direction=adparamoutput; //宣告是輸出引數

//輸出引數 descript

_parameterptr pparamdescript;

pparamdescript.createinstance("adodb.parameter");

pparamdescript->name="descript"; //引數名稱

pparamdescript->type=advarchar; //引數型別

pparamdescript->size=160; //引數大小

pparamdescript->direction=adparamoutput; //宣告是輸出引數

//執行儲存過程

pcommand->activeconnection=m_pconnection;

pcommand->commandtext="spiteminfo"; //儲存過程名稱

pcommand->commandtype=adcmdstoredproc; //表示為儲存過程adcmdstoredproc

pcommand->execute(null, null, adcmdstoredproc);

price=(float)(pparamprice->value);

descript = (char*)_bstr_t(pparamdescript->value);

return true;

}catch(_com_error e)

}

VC 連線oracle資料庫

1 導入庫檔案,並設定全域性連線字串 import c program files common files system ado msado60 backcompat i386.tlb no namespace rename eof endoffile connectionptr pconn nu...

VC 資料庫連線

1.建立基於對話方塊的mfc應用程式 放置乙個list box和乙個按鈕 2.在stdafx.h中加入 import c program files common files system ado msado15.dll no namespace rename eof rseof 3.在按鈕觸發事件...

VC 連線sql資料庫

include iostream.h 在vc 中使用ado開發資料庫之前,需要匯入ado類資料庫 import c program files common files system ado msado15.dll no namespace rename eof endoffile int main...