//注意:一定要添加这个:
//项目->添加引用->.NET->System.Data.OracleClient.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Data;
namespace LinkOrcale
{
class Program
{
static void Main(string[] args)
{
string ConnectionString="Data Source=orcl;user=scott;password=Admin518;";//写连接串
OracleConnection conn=new OracleConnection(ConnectionString);//创建一个新连接
try
{
conn.Open();
OracleCommand cmd=conn.CreateCommand();
cmd.CommandText="select * from emp";//在这儿写sql语句
OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象
while(odr.Read())//读取数据,如果odr.Read()返回为false的话,说明到记录集的尾部了
{
Console.WriteLine(odr.GetOracleNumber(0) + " " + odr.GetOracleString(1).ToString() + " " + odr.GetOracleString(2).ToString() + " " + odr.GetOracleNumber(3) + " "+odr.GetOracleDateTime(4));
//输出字段1,这个数是字段索引,
}
odr.Close();
}
catch(Exception e)
{
Console.WriteLine("出现异常"+e.GetBaseException());
}
finally
{
conn.Close(); //关闭连接
}
}
}
}