|
using System;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
namespace MultiTier.Data {
public abstract class OleDB : Data {
#region Enumerators
#endregion
#region Constructors
protected OleDB(string connection) : base(connection) {
}
#endregion
#region Variables
// Connection
private OleDbConnection cnConnection;
// DataAdapter
private OleDbDataAdapter daDataAdapter;
#endregion
#region Properties
public OleDbConnection Connection {
get { return cnConnection; }
set { cnConnection = value; }
}
public OleDbDataAdapter DataAdapter {
get { return daDataAdapter; }
set { daDataAdapter = value; }
}
#endregion
#region Methods
protected abstract override void ConstructDataAdapter();
public override DataTable ReadData() {
//--- Create a new DataSet
this.Table = new DataTable(this.TableName);
this.Table.Locale = CultureInfo.InvariantCulture;
try {
//--- Fill the DataSet with the Customers
daDataAdapter.Fill(this.Table);
//--- Return the DataSet
return this.Table;
}
catch (OleDbException ex) {
//--- An error occurred, so we roll the transaction back
this.CurrentException = ex;
//--- Return the DataSet
return this.Table;
}
}
public override void SaveData(DataTable dataTable) {
this.Table = dataTable;
OleDbTransaction trTransaction = null;
//---------------------------------------------------------
//--- Save the data
//---------------------------------------------------------
try {
//--- Set up the conection manually
InitializeConnection();
cnConnection.Open();
//--- Begin a transaction
trTransaction = cnConnection.BeginTransaction();
//--- Make all database changes
this.AffectedRecords = daDataAdapter.Update(this.Table);
//--- Commit the changes
trTransaction.Commit();
}
catch (DBConcurrencyException ex) {
//--- An error occurred, so we roll the transaction back
this.CurrentException = ex;
trTransaction.Rollback();
}
catch (OleDbException ex) {
//--- An error occurred, so we roll the transaction back
this.CurrentException = ex;
trTransaction.Rollback();
}
finally {
//--- Close the connection that we manually opened
trTransaction = null;
cnConnection.Close();
cnConnection = null;
}
}
public override void InitializeConnection() {
cnConnection = new OleDbConnection(this.ConnectionString);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I started using C# in the spring of 2003.
For the moment I'm working for a company that makes healthcare related software and do the ASP.NET programming in C# and VB.NET.