C# .NET开发Oracle数据库应用程序

  .NET Framework访问Oracle数据库至少有两种方式,一种是利用微软提供的ADO.NET,另一种是利用Oracle提供的ODP.NET。

  安装VS的时候会附带ADO.NET,安装Oracle客户端时会附带ODP.NET。

  在访问Oracle数据库方面,ODP.NET比上面所提到的其他数据库访问方案都强大和高效。

  从.NET Framework 4.5以后,微软将不再提供对Oracle数据库访问的支持,推荐使用第三方Oracle provider。

  下面的示例创建一个 OracleCommand 和一个 OracleConnection。 将 OracleConnection 打开并将其设置为 OracleCommand ..::.Connection 属性。 然后,该示例调用 ExecuteNonQuery 并关闭该连接。 为完成此任务,将为 ExecuteNonQuery 传递一个连接字符串和一个查询字符串,后者是一个 SQL INSERT 语句。  

 1 public void InsertRow(string connectionString)
 2 {
 3     string queryString = 
 4         "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
 5     using (OracleConnection connection = new OracleConnection(connectionString))
 6     {
 7         OracleCommand command = new OracleCommand(queryString);
 8         command.Connection = connection;
 9         try
10         {
11             connection.Open();
12             command.ExecuteNonQuery();
13         }
14         catch (Exception ex)
15         {
16             Console.WriteLine(ex.Message);
17         }
18     }
19 }

  未完,待续...

转载于:https://www.cnblogs.com/onedime/archive/2012/12/31/2840993.html

个人曾经写过的数据访问接口,包含:MSSQL、Mysql、Oracle数据库的公共处理接口。可以拿过来直接使用,放在手里好多年了。 IDatabase接口声明如下: namespace Simple.Database { /// /// IDatabase 接口 /// public interface IDatabase { DbConnection dbConn { get; set; } /// /// 创建 DbConnection 对象实例。 /// /// DbConnection 对象实例。 DbConnection CreateConnection(); /// /// 创建 DbCommand 对象实例。 /// /// DbCommand 对象实例。 DbCommand CreateCommand(); /// /// 创建 DbCommand 对象实例。 /// /// Sql 语句或存储过程名。 /// CommandType 参数。 /// DbCommand 对象实例。 DbCommand CreateCommand(string text, CommandType type); /// /// 创建 DbCommand 对象实例。 /// /// Sql 语句或存储过程名。 /// CommandType 参数。 /// 参数集合。 /// DbCommand 对象实例。 DbCommand CreateCommand(string text, CommandType type, IDataParameter[] paras); /// /// 创建 DbCommand 对象实例。 /// /// DbConnection 对象。 /// Sql 语句或存储过程名。 /// CommandType 参数。 /// 参数集合。 /// DbCommand 对象实例。 DbCommand CreateCommand(DbConnection conn, string text, CommandType type, IDataParameter[] paras); /// /// 创建 DbDataAdapter 对象实例。 /// /// DbDataAdapter 对象实例。 DbDataAdapter CreateDataAdapter(); /// /// 创建 DbParameter 对象实例。 /// /// DbParameter 对象实例。 DbParameter CreateParameter(); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数值。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, Object value); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数类型。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, DbType type); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数类型。 /// 数据的最大大小。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, DbType type, int size); /// /// 获取指定长度数据的 DataSet 对象。 /// /// 要读取的 Sql 语句。 /// 开始读取位置的索引。 /// 待读取记录集的长度。 /// DataSet 对象。 DataSet GetDataSet(string sql, int start, int length); /// /// 获取指定长度数据的 DataTable 对象。 /// /// 要读取的 Sql 语句。 /// 开始读取位置的索引。 /// 待读取记录集的长度。 /// DataTable 对象。 DataTable GetDataTable(string sql, int start, int length); /// /// 执行Insert、Update、Delete等操作,并返回受影响的记录数。 /// /// 要执行的 Sql 语句。 /// 受影响的记录数。 int GetEffect(string sql); /// /// 执行 Insert、Update、Delete 等操作,并返回受影响的记录数。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 的类型,即该命令是 Sql 语句,还是存储过程名等。 /// 受影响的记录数。 int GetEffect(string sql, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回受影响的记录数。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// 受影响的记录数。 int GetEffect(string text, CommandType type, IDataParameter[] paras); /// /// /// /// /// /// /// /// /// int GetEffect(DbConnection conn, string text, CommandType type, IDataParameter[] paras, DbTransaction DbTrans); /// /// /// /// /// List ExecuteTransaction(params string[] sqls); /// /// 执行 Select 语句,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句。 /// DataSet 对象。 DataSet GetDataSet(string sql); /// /// 执行 Select 语句或存储过程,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// DataSet 对象。 DataSet GetDataSet(string text, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// DataSet 对象。 DataSet GetDataSet(string text, CommandType type, IDataParameter[] paras); /// /// 执行 Select 语句,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句。 /// DataTable 对象。 DataTable GetDataTable(string sql); /// /// 执行 Select 语句或存储过程,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// DataTable 对象。 DataTable GetDataTable(string text, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// DataTable 对象。 DataTable GetDataTable(string text, CommandType type, IDataParameter[] paras); /// /// 获取查询所返回的结果集中第一行第一列的值。 /// /// 要处理的 sql 语句(包含待查询的字段)。 /// 字段值。 object GetField(string sql); /// /// 获取查询所返回的结果集中第一行指定列的值。 /// /// 待查询的数据表名称。 /// 待获取字段的列名。 /// 字段值。 object GetField(string sql, string field); /// /// 获取查询所返回的结果集中第一行指定列集合的值。 /// /// 要处理的 sql 语句。 /// 待获取字段的列表。 /// 字段值集合。 object[] GetField(string sql, params string[] fields); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值