Click here to Skip to main content
15,886,026 members
Articles / Web Development / ASP.NET

A Task Management System using Three Layer Architecture

,
Rate me:
Please Sign up or sign in to vote.
4.27/5 (15 votes)
9 Apr 2010CPOL5 min read 64.3K   3.5K   54  
This describes a three Layer Architecture with examples
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataExecuteClass
/// </summary>
public class DataExecuteClass
{
    public DataExecuteClass()
    {
    }
    public static string st = System.Configuration.ConfigurationManager.ConnectionStrings["TaskManagementSystemDBConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(st);
    SqlCommand cmd = null;
    SqlDataAdapter adapter = null;
    DataSet ds = null;


    public DataSet getDataSet(string query)
    {
        try
        {
            con = new SqlConnection(st);
            con.Open();
            ds = new DataSet();
            cmd = new SqlCommand(query, con);
            adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            adapter = null;
            cmd = null;

            query = null;

            con.Close();
        }
        return ds;
    }
    public void ExecuteNonQuery(string query)
    {


        try
        {
            con = new SqlConnection(st);
            cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
            cmd = null;
            con = null;
            query = null;
        }
    }
    public object getSingleValue(string query)
    {
        con = new SqlConnection(st);

        try
        {
            con = new SqlConnection(st);
            cmd = new SqlCommand(query, con);
            con.Open();
            object retValue = cmd.ExecuteScalar();
            return retValue;
        }
        catch (Exception ex)
        {
            return (object)ex.Message.ToString();
        }
        finally
        {
            con.Close();
            cmd = null;
            con = null;
            query = null;

        }
    }
}

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
Software Developer Waveroamer Solutions, Advanced ERP(BD) LTD
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Software Developer WaveRoamer Solution Ltd
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions