日期:2010-06-11 浏览次数:20480 次
using System;
using System.Data;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Collections;
using System.Configuration;
namespace OraHelper
{
public abstract class OraHelper
{
public static readonly string CONN_STRING_NON_DTC = ConfigurationSettings.AppSettings["ConnStr"].Trim();
public static OracleConnection conn = new OracleConnection(CONN_STRING_NON_DTC);
public static void OpenConnection()
{
if (conn.State != ConnectionState.Open)
conn.Open();
}
public static void CloseConnection()
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
public static DataSet getDataSet(string cmdText)
{
OracleDataAdapter Adapter = new OracleDataAdapter(cmdText,conn);
DataSet Data = new DataSet();
Adapter.Fill(Data);
return Data;
}
public static OracleDataReader ExecuteReader(string cmdText)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection=conn;
cmd.CommandText=cmdText;
OracleDataReader rdr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return rdr;
}
public static int ExecuteNonQuery(string cmdText)
{
try
{
OracleCommand comm=new OracleCommand(cmdText,conn);
comm.ExecuteNonQuery();
return 1;
}
catch
{
return 0;
}
}
public static void ExecuteNonQuery(string cmdText,OracleConnection conn)
{
try
{
OracleCommand comm=new OracleCommand(cmdText,conn);
comm.ExecuteNonQuery();
}
catch
{
}
}
public static string ExecuteScalar(string cmdText)
{
string status="";
try
{
OracleCommand comm=new OracleCommand(cmdText,conn);
status=comm.ExecuteScalar().ToString();
return status;
}
catch(Exception err)
{
//return "-1";
return err.Message.ToString();
}
}
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.Parameters.Clear();
cmd.CommandText=cmdText;
foreach (OracleParameter parm in cmdParms)