Oracle C 連線Oracle資料庫

2022-08-05 16:33:10 字數 1499 閱讀 6675

1、確保已安裝oracle客戶端,已建立資料庫

2、在專案中安裝oracle.manageddataaccessnuget包

在vs中工具——nuget包管理器——管理解決方案的nuget程式包——搜尋安裝即可(確保聯網)

3、新增引用using oracle.manageddataaccess.client;

4、建立查詢方法

確定連線字串:

data source:資料來源

# generated by oracle configuration tools.

listener_orcl =

(address = (protocol = tcp)(host = localhost)(port = 1521))

oraclr_connection_data =

(description =

(address_list =

(address = (protocol = ipc)(key = extproc1521))

)(connect_data =

(sid = clrextproc)

(presentation = ro)

))orcl =

(description =

(address = (protocol = tcp)(host = localhost)(port = 1521))

(connect_data =

(server = dedicated)

(service_name = orcl)

))連線字串data source為最後一部分

(description =

(address = (protocol = tcp)(host = localhost)(port = 1521))

(connect_data =

(server = dedicated)

(service_name = orcl)))

user id:使用者名稱

password:安裝時設定的口令(密碼)

public datatable exportdatatable(string tablename, string selectstr)

trywhere ";

oraclecommand command = new oraclecommand(cmdstr, con);

oracledataadapter adapter = new oracledataadapter(command);

adapter.fill(dt);}}

catch (exception)

return dt;

}