资源简介
微软些的C# OracleHelper,有兴趣的参考下
代码片段和文件信息
using System;
using System.Configuration;
using System.Data;
using System.Data.OracleClient;
using System.Collections;
using System.Data.OleDb;
namespace Data.OracleDataProvider
{
///
/// A helper class used to execute queries against an Oracle database
///
public abstract class OracleHelper {
public static readonly string ConnectionString = ConfigurationManager.ConnectionStrings[“OracleConnString“].ConnectionString;
// Read the connection strings from the configuration file
//Create a hashtable for the parameter cached
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
///
/// Execute a database query which does not include a select
///
/// Connection string to database
/// Command type either stored procedure or SQL
/// Acutall SQL Command
/// Parameters to bind to the command
///
public static int ExecuteNonQuery(string connectionString CommandType cmdType string cmdText params OracleParameter[] commandParameters) {
// Create a new Oracle command
OleDbCommand cmd = new OleDbCommand();
//Create a connection
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
//Prepare the command
PrepareCommand(cmd connection null cmdType cmdText commandParameters);
//Execute the command
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
///
/// Execute an OleDbCommand (that returns no resultset) against an existing database transaction
/// using the provided parameters.
///
///
/// e.g.:
/// int result = ExecuteNonQuery(trans CommandType.StoredProcedure “PublishOrders“ new OracleParameter(“:prodid“ 24));
///
/// an existing database transaction
/// the CommandType (stored procedure text etc.)
/// the stored procedure name or PL/SQL command
/// an array of OracleParamters used to execute the command
/// an int representing the number of rows affected by the command
public static int ExecuteNonQuery(OleDbTransaction trans CommandType cmdType string cmdText params OracleParameter[] commandParameters) {
OleDbCommand cmd = new OleDbCommand();
PrepareCommand(cmd trans.Connection trans cmdType
评论
共有 条评论