Thursday, 3 September 2015

Three Layer

<configuration>
  <connectionStrings>
    <add name="Mythreetier" connectionString="Data Source=guru\sqlexpress;Initial Catalog=ProjectBilling;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>


using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace DatabaseLayer
{
    public class clsDataLayer
    {
    private string conn = ConfigurationManager.ConnectionStrings["Mythreetier"].ToString();
 
        public void InsertUpdateDeleteSQLString(string sqlstring)

        {
            SqlConnection objsqlconn = new SqlConnection(conn);
           if (objsqlconn.State == ConnectionState.Closed)
            {
                objsqlconn.Open();
            }           
            SqlCommand objcmd = new SqlCommand(sqlstring, objsqlconn);
            objcmd.ExecuteNonQuery();
        }

 
        public object ExecuteSqlString(string sqlstring)

        {
            SqlConnection objsqlconn = new SqlConnection(conn);
            if (objsqlconn.State == ConnectionState.Closed)
            {
                objsqlconn.Open();
            }  
            DataSet ds = new DataSet();
            SqlCommand objcmd = new SqlCommand(sqlstring, objsqlconn);
            SqlDataAdapter objAdp = new SqlDataAdapter(objcmd);
            objAdp.Fill(ds);
            return ds;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DatabaseLayer

namespace BusinessLayer
{
    public class clsBusinessLayer
    {
        public clsDataLayer objDataLayer = new clsDataLayer();
        public void AddNewCustomer(string custname, string custaddr, string custcountry, string custcity, string custincode)

        {
            objDataLayer.AddNewCustomerDB(custname, custaddr, custcountry, custcity, custincode);

        }



        public void UpdateCustomer(int custid, string custname, string custaddr, string custcountry, string custcity, string custincode)

        {

            objDataLayer.UpdateCustomerDB(custid, custname, custaddr, custcountry, custcity, custincode);

        }

 

        public void DeleteCustomer(int custid)
        {
            objDataLayer.DeleteCustomerDB(custid);
        }

        public object LoadCustomer()

        {
            return objDataLayer.LoadCustomerDB();
        }
    }
}