C#连接并操作Oracle数据库
C#连接并操作Oracle数据库
1.NuGet安装Oracle.ManagedDataAccess
2.引用
using Oracle.ManagedDataAccess;
using Oracle.ManagedDataAccess.Types;
using Oracle.ManagedDataAccess.Client;
3.Action
public OperationResult InsertDate(string order)
{
//String constr = “User ID=USER1;Password=pass;Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST=1.1.1.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DBDEV)))”;
string constr = System.Configuration.ConfigurationManager.AppSettings[“DBOA”];
OracleConnection con = new OracleConnection(constr);
//System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(constr);
con.Open(); //建立连接,打开数据库
OperationResult returnResult = new OperationResult();
try
{
returnResult.Errors.Add(“成功连接数据库!”);
var id = “1”;
var pass = “2”;
string sql = “insert into temp (fd_B,status) values (‘B5′,’5’)”;
//string sql = “select count(*) from spare_part_temp”;
// SqlCommand com = new SqlCommand(sql, con);
OracleCommand oc = new OracleCommand(sql, con);
int result = oc.ExecuteNonQuery();
JeffSoft.Logger.Error(string.Format(“成功读取{0},条记录”, result));
//int Succnum = com.ExecuteNonQuery();
//结果集保存
con.Close();
return returnResult;
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
}