首先添加.Net的引用System.Data.OracleClient到项目中;
app.config配置连接字符串:<add name="OracleConn" connectionString="Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=服务器的IP地址)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=数据库名称)));User ID=用户名;Password=密码;Unicode=True" providerName="System.Data.OracleClient"/>
然后class类中调用:
string strConn = ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString;
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbCommand comm = new OleDbCommand("select xf_plu,xf_desci from (select xf_plu,xf_desci from xf_itemmas order by rownum) where rownum <= 10", conn);
OleDbDataReader dr = comm.ExecuteReader();
Console.WriteLine("商品码 商品描述");
while (dr.Read())
{
Console.WriteLine(dr.GetString(0) + " " + dr.GetString(1));
}
Console.ReadLine();
dr.Close();
conn.Close();