Naar inhoud springen

Programmeren in ASP.net 2.0 N-Tier Tutorial/Data Access Laag/DataAccessor.cs

Uit Wikibooks

C#-code: "DataAccessor.cs"

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

using MessageBoard.Common;

namespace MessageBoard.DataAccess
{
	public abstract class DataAccessor : IDisposable
	{
		Database _db;

		public DataAccessor()
		{
			string connectionStringName = ConfigurationManager.AppSettings["connectionStringName"];
			_db = Database.GetInstance(connectionStringName);
		}

		protected Database Database
		{
			get
			{
				return _db;
			}
		}

		protected abstract DbCommand GetInsertCommand();
		protected abstract DbCommand GetUpdateCommand();
		protected abstract DbCommand GetDeleteCommand();

		#region IDisposable Members

		protected void Update(DataSet ds, string tableName)
		{
			Database.UpdateDataSet(ds, tableName, GetInsertCommand(), GetUpdateCommand(), GetDeleteCommand());
		}

		protected void Update(DbTransaction trans, DataSet ds, string tableName)
		{
			Database.UpdateDataSet(trans, ds, tableName, GetInsertCommand(), GetUpdateCommand(), GetDeleteCommand());
		}

		public void Dispose()
		{
			Database.Dispose();
		}

		#endregion
	}
}

Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.