Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Database Helper Class Library to Ease Database Operation

, 14 Apr 2007 CPOL
Database Helper Class Library to Ease Database Operation
article_demo.zip
DBHelperQuickRelationshipSamples
DBHelperQuickRelationshipSamples
App.ico
DBHelperQuickRelationshipSamples.csproj.user
DBHelperQuickRelationshipSamples.suo
DBHelperQuickSelectSamples
DBHelperQuickSelectSamples
DBHelperQuickSelectSamples.csproj.user
DBHelperQuickSelectSamples.suo
DBHelperQuickHelperSamples
DBHelperQuickHelperSamples
App.ico
DBHelperQuickHelperSamples.csproj.user
DBHelperQuickHelperSamples.suo
DBHelperQuickInsUpdDelSamples
DBHelperQuickInsUpdDelSamples
DBHelperQuickInsUpdDelSamples.csproj.user
DBHelperQuickInsUpdDelSamples.suo
article_src.zip
Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces
Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces.csproj.user
Microsoft.ApplicationBlocks.ExceptionManagement.suo
DbHelper
DBHelper.chm
DBHelper.csproj.user
DbHelper.ndoc
DBHelper.suo
Microsoft.ApplicationBlocks.ExceptionManagement
ExceptionManagerText.xsx
Microsoft.ApplicationBlocks.ExceptionManagement.csproj.user
Microsoft.ApplicationBlocks.suo
///////////////////////////////////////////////////////////////////////////
// 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)

Share

About the Author

falconsoon

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 14 Apr 2007
Article Copyright 2007 by falconsoon
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid