仿照http://blog.csdn.net/makenothing/article/details/17080069
1 建立Oracle連接 VS2010中添加數據庫連接
得到連接字符串
Data Source=server1;Persist Security Info=True;User ID=s227;Password=×××;Unicode=True ×××為你的密碼
2 建立VS2010 C#控制台程序
因為這個是示例程序 控制台比較方便
在引用中添加 System.Data.OracleClient 引用(Framwork 4.0之下有這個引用) 具體可以看下我開頭給出的網址 裡面有差錯的程序
然後 using System.Data.OracleClient
3 示例程序 走起
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.OracleClient; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string connString = "Data Source=server1;Persist Security Info=True;User ID=s227;Password=123;Unicode=True"; string queryString = "SELECT * FROM PRODUCT "; OracleConnection conn = new OracleConnection(connString); conn.Open(); OracleCommand command = new OracleCommand(queryString,conn); OracleDataReader reader = command.ExecuteReader(); reader.Read(); Console.WriteLine("1 "+reader["MAKER"]+" 2 "+reader["MODEL"]+" 3 "+reader["TYPE"]); reader.Close(); conn.Close(); /* * //學習的代碼塊 string connectionString; string queryString; connectionString = "Data Source=202.200.136.125/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(); */ } } }
輸出 1 A 2 1001 3 PC
這個輸出與你的queryString
也就是查詢語句有關系