C#连接Oracle
2017-08-25 00:06 lijianhua 阅读(196) 评论(0) 编辑 收藏 举报2.Oracle自己提供的方法:using Oracle.DataAccess.Client;
前提条件:安装oracle或者oracle client以及安装 Oracle Client 。
··2.右键、引用,在.NET/组件中选择Oracle.DataAccess.Client;如果找不到则选择 浏览,进入到oracleclient的安装目录寻找 Oracle.Data.Access.dll (典型目录为:E:\app\Administrator\product\11.2.0\client_1\ODP.NET\bin\2.x\Oracle.Data>Access.dll)
··3.程序中添加引用:using Oracle.DataAccess.Client;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Oracle.DataAccess.Client; namespace testConnectionOracle { class Program { static void Main( string [] args) { string connectionString; string queryString; connectionString = "Data Source=202.200.155.123/orcl;User ID=openlab;PassWord=open123" ; queryString = "SELECT * FROM T_USER" ; OracleConnection myConnection = new OracleConnection(connectionString); OracleCommand myORACCommand = myConnection.CreateCommand(); myORACCommand.CommandText = queryString; myConnection.Open(); OracleDataReader myDataReader = myORACCommand.ExecuteReader(); myDataReader.Read(); Console.WriteLine( "email: " + myDataReader[ "EMAIL" ]); myDataReader.Close(); myConnection.Close(); } } } |