using System.Data.SqlClient;
using System.Configuration;
using Oracle.DataAccess.Client;
using System.Collections;
public static SqlConnection CPCIS1Conn = new SqlConnection(ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString());
public static OracleConnection ORASRVConn = new OracleConnection(ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString());
public static ArrayList tSQL = new ArrayList();
public static ArrayList oSQL = new ArrayList();
protected DataTable GetDataSQL(string Command, string TableName)
{
DataTable Dt = new DataTable();
CPCIS1Conn.Close();
CPCIS1Conn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
SqlCommand cmd = new SqlCommand(sTranstionSql, CPCIS1Conn);
SqlDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
CPCIS1Conn.Close();
return Dt;
}
protected DataTable GetDataORACLE(string Command, string TableName)
{
DataTable Dt = new DataTable();
ORASRVConn.Close();
ORASRVConn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
OracleCommand cmd = new OracleCommand(sTranstionSql, ORASRVConn);
OracleDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
ORASRVConn.Close();
return Dt;
}
protected bool WriteDataSQL(ArrayList SQL)
{
try
{
SqlCommand DBCommand = new SqlCommand();
SqlTransaction DBTransaction;
SqlConnection DBConnection = new SqlConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction("SQLTransaction");
DBCommand.Connection = DBConnection;
DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
tSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
tSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
tSQL.Clear();
throw new Exception(ex.Message);
}
}
protected bool WriteDataORACLE(ArrayList SQL)
{
try
{
OracleCommand DBCommand = new OracleCommand();
OracleTransaction DBTransaction;
OracleConnection DBConnection = new OracleConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction();
DBCommand.Connection = DBConnection;
//DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
//DBTransaction.Rollback();
oSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
oSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
oSQL.Clear();
throw new Exception(ex.Message);
}
}
沒有留言:
張貼留言