VS.Net2005连接Oracle数据库

创建C#控制台项目.首先引用system.oracle.dll,然后在类文件中键入如下代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace ConnectOracle
{
class Program
{
static void Main(string[] args)
{

//server=数据库Sid的名字
OracleConnection con = new OracleConnection("server=student;user id=scott;password=tiger");
//OracleDataAdapter da = new OracleDataAdapter("select * from demo",con);

//demo是oracle数据库中的表名
OracleCommand com = new OracleCommand("select * from demo",con);
con.Open();
OracleDataReader dr = com.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[0]);
Console.WriteLine(dr.GetValue(1).ToString());
}
dr.Close();
con.Close();

}
}
}

你可能感兴趣的:(oracle数据库)