Click here to Skip to main content
15,886,689 members
Articles / Database Development / SQL Server

Database Helper Class Library to Ease Database Operation

Rate me:
Please Sign up or sign in to vote.
3.09/5 (9 votes)
14 Apr 2007CPOL4 min read 87.6K   3K   57  
Database Helper Class Library to Ease Database Operation
///////////////////////////////////////////////////////////////////////////
// Copyright 2003-2005 Falcon Soon
//
// Author: Soon Chun Boon
// Date: 10 Jan 2004
// Description: 
// Base class for Database Interaction.
// Because this class implements IDisposable, derived classes shouldn't do so.
// This class is taken from codes generated by LLBLGen v1.21.2003.712
///////////////////////////////////////////////////////////////////////////

using System;
using System.Data;

namespace DBHelper
{
	/// <summary>
	/// Error Enums used by this library.
	/// </summary>
	public enum DBError
	{
        /// <summary>
        /// Everyting is Ok.
        /// </summary>
		AllOk
		// Add more here (check the comma's!)
	}


	/// <summary>
	/// General interface which contains only common database methods of all classes.
	/// </summary>
	public interface ICommonDBAccess
	{
        /// <summary>
        /// General signature for database insert operation.
        /// </summary>
        /// <returns>True if successful.</returns>
		bool		Insert();

        /// <summary>
        /// General signature for database update operation.
        /// </summary>
        /// <returns>True if successful.</returns>
		bool		Update();

        /// <summary>
        /// General signature for database delete operation.
        /// </summary>
        /// <returns>True if successful.</returns>
		bool		Delete();

        /// <summary>
        /// General signature for database select operation based on select criteria.
        /// </summary>
        /// <returns>A <see cref="System.Data.DataTable"/> consists of selected rows.</returns>
		DataTable	SelectSome();

        /// <summary>
        /// General signature for database select all operation.
        /// </summary>
        /// <returns>A <see cref="System.Data.DataTable"/> consists of all rows in database.</returns>
		DataTable	SelectAll();

        /// <summary>
        /// General signarute for database operation using <see cref="System.Data.Common.DataAdapter.Update"/>.
        /// </summary>
        /// <returns>The number of rows successfully updated.</returns>
        int         DBAdapterUpdate();

        /// <summary>
        /// Specifies fields to select from database.
        /// </summary>
        string FieldsToSelect
        {
            get;
            set;
        }

        /// <summary>
        /// Specifies fields to update to database.
        /// </summary>
        string FieldsToUpdate
        {
            get;
            set;
        }

        /// <summary>
        /// Specifies filter expression for select operation.
        /// </summary>
        string SelectCriteria
        {
            get;
            set;
        }

        /// <summary>
        /// Specifies filter expression for update operation.
        /// </summary>
        string UpdateCriteria
        {
            get;
            set;
        }

        /// <summary>
        /// Specifies filter expression for delete operation.
        /// </summary>
        string DeleteCriteria
        {
            get;
            set;
        }
	}


	/// <summary>
	/// Abstract base class for Database Interaction classes.
	/// </summary>
	public abstract class DBInteractionBase
	{
		#region Class Member Declarations
            /// <summary>
            /// Number of rows affected by database operation.
            /// </summary>
			protected	int						miRowsAffected;

            /// <summary>
            /// Error code.
            /// </summary>
			protected	int     				miErrorCode;

            /// <summary>
            /// Connection string.
            /// </summary>
			protected	string					mstrConnectionString;
		#endregion


		/// <summary>
		/// Protected class constructor.
		/// </summary>
		protected DBInteractionBase()
		{
			// Initialize the class' members.
			InitClass();
		}


		/// <summary>
		/// Initializes class members.
		/// </summary>
		protected virtual void InitClass()
		{
			// create all the objects and initialize other members.
            miRowsAffected = 0;
			miErrorCode = (int)DBError.AllOk;
            mstrConnectionString = "";
		}


		#region Class Property Declarations
        /// <summary>
        /// Return error code.
        /// </summary>
		public int ErrorCode
		{
			get
			{
				return (miErrorCode);
			}
		}

        /// <summary>
        /// Specifies connection string.
        /// </summary>
		public virtual string ConnectionString
		{
			get
			{
				return (mstrConnectionString);
			}
			set
			{
				mstrConnectionString = value;
			}
		}

        /// <summary>
        /// Returns rows affected by database operation.
        /// </summary>
		public int RowsAffected
		{
			get
			{
				return (miRowsAffected);
			}
		}
		#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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Malaysia Malaysia
Had worked as analyst programmer for 4 years. Now helping in family business but still involved actively in .Net development whenever there is a free time.

Comments and Discussions