仿照http://blog.csdn.net/makenothing/article/details/17080069
1 建立Oracle连接 VS2010中加入数据库连接
得到连接字符串
Data Source=server1;Persist Security Info=True;User ID=s227;Password=×××;Unicode=True ×××为你的password
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
也就是查询语句有关系
时间: 2024-10-10 23:11:55