C# ManagedDataAccess 操作oracle数据库
甲骨文官方制作的oracle类库
优点是无需安装oracle客户端
环境准备
Nuget安装
- Oracle.ManagedDataAccess
引用
using Oracle.ManagedDataAccess.Client;
连接oracle数据库
- 连接字符串
connStr = @"Data Source=连接源;User Id=tp_pblm;Password=Rbsy_8JHbgRF;";
连接源替换成tnsname.ora中的连接字符串
- 连接代码
using (OracleConnection conn = new OracleConnection(connStr))
{
conn.Open();
}
查询
public static DataTable ExecuteDataTable(string sql, params OracleParameter[] parameters)
{
using (OracleConnection conn = new OracleConnection(connStr))
{
conn.Open();
using (OracleCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameters);
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
DataTable datatable = new DataTable();
adapter.Fill(datatable);
return datatable;
}
}
}