OLEDB SqlHelper
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
namespace MyLib.Data
{
public sealed class CDBConn
{
// Methods
public CDBConn()
{
this.m_bIsInTransaction = false;
this.m_Timeout = 30;
this.m_objConn = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectString"]);
this.m_objConn.Open();
}
public CDBConn(bool bOpenNow)
{
this.m_bIsInTransaction = false;
this.m_Timeout = 30;
this.m_objConn = new OleDbConnection(ConfigurationSettings.AppSettings["ConnectString"]);
if (bOpenNow)
{
this.m_objConn.Open();
}
}
public CDBConn(string strConnectionString)
{
this.m_bIsInTransaction = false;
this.m_Timeout = 30;
this.m_objConn = new OleDbConnection(strConnectionString);
this.m_objConn.Open();
}
public CDBConn(string strConnectionString, bool bOpenNow)
{
this.m_bIsInTransaction = false;
this.m_Timeout = 30;
this.m_objConn = new OleDbConnection(strConnectionString);
if (bOpenNow)
{
this.m_objConn.Open();
}
}
public void BeginTransaction()
{
if (!this.m_bIsInTransaction)
{
this.m_objCommand = new OleDbCommand();
this.m_objCommand.Connection = this.m_objConn;
this.m_objTransaction = this.m_objConn.BeginTransaction();
if (this.m_Timeout >= 30)
{
this.m_objCommand.CommandTimeout = this.m_Timeout;
}
this.m_objCommand.Transaction = this.m_objTransaction;
this.m_bIsInTransaction = true;
}
}
public void Close()
{
if (this.m_objConn.State != ConnectionState.Closed)
{
this.m_objConn.Close();
}
}
public void Commit()
{
if (this.m_bIsInTransaction)
{
this.m_objTransaction.Commit();
this.m_bIsInTransaction = false;
this.m_objCommand.Dispose();
}
}
public void Dispose()
{
if (this.m_objConn.State != ConnectionState.Closed)
{
this.m_objConn.Close();
}
this.m_objConn.Dispose();
}
public DataSet ExecuteDataSet(string strSQL)
{
DataSet set1 = new DataSet();
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
OleDbDataAdapter adapter1 = new OleDbDataAdapter(command1);
adapter1.Fill(set1);
command1.Dispose();
adapter1.Dispose();
return set1;
}
public DataSet ExecuteDataSet(string strSQL, string strTable)
{
DataSet set1 = new DataSet();
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
OleDbDataAdapter adapter1 = new OleDbDataAdapter(command1);
adapter1.Fill(set1, strTable);
command1.Dispose();
adapter1.Dispose();
return set1;
}
public OleDbDataReader ExecuteReader(string strSQL)
{
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
OleDbDataReader reader1 = command1.ExecuteReader();
command1.Dispose();
return reader1;
}
public void ExecuteSQL(string strSQL)
{
if (!this.m_bIsInTransaction)
{
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
command1.ExecuteNonQuery();
command1.Dispose();
}
else
{
this.m_objCommand.CommandText = strSQL;
this.m_objCommand.ExecuteNonQuery();
}
}
public int FillDataSet(ref DataSet objDataSet, string strSQL)
{
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
OleDbDataAdapter adapter1 = new OleDbDataAdapter(command1);
int num1 = adapter1.Fill(objDataSet);
command1.Dispose();
adapter1.Dispose();
return num1;
}
public int FillDataSet(ref DataSet objDataSet, string strSQL, string strTable)
{
OleDbCommand command1 = new OleDbCommand(strSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
OleDbDataAdapter adapter1 = new OleDbDataAdapter(command1);
int num1 = adapter1.Fill(objDataSet, strTable);
command1.Dispose();
adapter1.Dispose();
return num1;
}
~CDBConn()
{
}
public bool Lock(string[] strArrTableName)
{
return true;
// return this.m_objSync.Lock(strArrTableName);
}
public void Open()
{
if (this.m_objConn.State != ConnectionState.Open)
{
this.m_objConn.Open();
}
}
public void Rollback()
{
if (this.m_bIsInTransaction)
{
this.m_objTransaction.Rollback();
this.m_bIsInTransaction = false;
this.m_objCommand.Dispose();
}
}
public void Update(string strSelectSQL, DataSet objDataSet)
{
OleDbDataAdapter adapter1;
OleDbCommandBuilder builder1;
if (!this.m_bIsInTransaction)
{
OleDbCommand command1 = new OleDbCommand(strSelectSQL, this.m_objConn);
if (this.m_Timeout >= 30)
{
command1.CommandTimeout = this.m_Timeout;
}
adapter1 = new OleDbDataAdapter(command1);
builder1 = new OleDbCommandBuilder(adapter1);
adapter1.InsertCommand = builder1.GetInsertCommand();
adapter1.DeleteCommand = builder1.GetDeleteCommand();
adapter1.UpdateCommand = builder1.GetUpdateCommand();
adapter1.Update(objDataSet);
builder1.Dispose();
command1.Dispose();
adapter1.Dispose();
}
else
{
adapter1 = new OleDbDataAdapter(this.m_objCommand);
builder1 = new OleDbCommandBuilder(adapter1);
adapter1.InsertCommand = builder1.GetInsertCommand();
adapter1.DeleteCommand = builder1.GetDeleteCommand();
adapter1.UpdateCommand = builder1.GetUpdateCommand();
adapter1.Update(objDataSet);
builder1.Dispose();
adapter1.Dispose();
}
}
// Properties
public ConnectionState State
{
get
{
return this.m_objConn.State;
}
}
public int Timeout
{
get
{
return this.m_Timeout;
}
set
{
if (value < 1)
{
this.m_Timeout = 1;
}
else
{
this.m_Timeout = value;
}
}
}
// Fields
private bool m_bIsInTransaction;
private OleDbCommand m_objCommand;
private OleDbConnection m_objConn;
private OleDbTransaction m_objTransaction;
private int m_Timeout;
}
}
-----------------------------------------------------------------------
相關文章
- SqlHelper:SQL
- SQLHelper 2.0SQL
- SqlHelper和DBHelperSQL
- .NET中封裝SqlHelper封裝SQL
- 微軟原版SQLHelper類微軟SQL
- oledb連線加密access加密
- 【.net基礎】--SQLHelper重構SQL
- OleDb匯出標準格式EXCEL,Excel
- sqlHelper類的中文 詳細註釋SQL
- 分享一個自己寫的C# SqlHelperC#SQL
- 幾種連線資料庫的OLEDB驅動程式資料庫
- 【學習筆記】ASP.NET簡易的SQLHelper幫助類筆記ASP.NETSQL
- C# SQLiteHelper類似SqlHelper類實現存取Sqlite資料庫C#SQLite資料庫
- 未在本地計算機下注冊“Microsoft.Jet.OLEDB.4.0”提供程式計算機ROS
- The ‘Microsoft.ACE.OLEDB.12.0′ provider is not registered on the local machine. (System.Data)ROSIDEMac
- ORA-00937 Errors While Executing A Query Using Microsoft OLEDB DriversErrorWhileROS
- Oledb操作Excel時欄位最大值255的問題解決方案Excel
- sqlhelper整合dynamic多資料來源的分頁問題(非教學向)SQL
- Linked Server: EXECUTE permission denied on object 'xp_prop_oledb_provider', database 'master', owne...ServerObjectIDEDatabaseAST
- Windows(64位IIS)未在本地計算機上註冊“Microsoft.Jet.OLEDB.4.0”提供程式Windows計算機ROS
- C#“未在本地計算機上註冊“Microsoft.ACE.OLEDB.12.0”提供程式”的解決方案C#計算機ROS
- 關於SQL Server通過OLEDB訪問ORACLE資料表涉及CLOB或BLOB欄位的錯誤提示SQLServerOracle
- 關於SQL Server通過OLEDB訪問ORACLE資料表涉及Oracle11g新增欄位的錯誤提示SQLServerOracle
- 轉載-64位SQL Server 2008的Linked Server連線64位的Oracle--Oracle Provider for OLEDBSQLServerOracleIDE