Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all ....
i want to use sqlhelperclass in my 3-tier architec. project. My company uses sqlhelper class and don't work on with DAL. so my question is how to use sqlhelperclass in DAL. My boss is saying i have not worked as per their req.How can i use the sqlhelperclass in following code and make my small proj. run.
code in BAL:
C#
using Datalgc;


namespace Buss
{
    public class BusinessLogic
    {
           public int Insert(string Name, DateTime DOB,string Addr,int phn,string Country,string State,string City)
        {

            BusinessLogic  pDAL = new BusinessLogic();

            try
            {

                return pDAL.Insert(Name,DOB , Addr ,phn ,Country,State,City);

            }

            catch
            {

                throw;

            }

            finally
            {

                pDAL = null;

            }

        }

    }

}

also code in DAL:
using System.Data;
using DL;

namespace Datalgc
{       
    public class Class1
    {
        string connStr = ConfigurationManager.ConnectionStrings["spuserdetails"].ToString();
        
        public int Insert(string Name, DateTime DOB, string  Addr,int phno,string Country,string State,String City)
        {
            SqlHelper.
            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();

            SqlCommand Cmd = new SqlCommand("spuserdetails", conn);

           Cmd.CommandType = CommandType.StoredProcedure;


            try
            {

                Cmd.Parameters.AddWithValue("@Name", Name);

                Cmd.Parameters.AddWithValue("@DOB", DOB);

                Cmd.Parameters.AddWithValue("@Addr", Addr);
                Cmd.Parameters.AddWithValue("@phno", phno);
                Cmd.Parameters.AddWithValue("@Country", Country);
                Cmd.Parameters.AddWithValue("@State", State);
                Cmd.Parameters.AddWithValue("@City", City);
                return Cmd.ExecuteNonQuery();

            }

            catch
            {

                throw;

            }

            finally
            {

                Cmd.Dispose();

                conn.Close();

                conn.Dispose();

            }

        }

    }
}

code for code behind file:
using BAL;  


public partial class _Default : System.Web.UI.Page 
{
    Class1 obj =new Class1();
           
       
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        DropDownList1.ClearSelection();
        DropDownList2.ClearSelection();
        DropDownList3.ClearSelection();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList3.DataSource = 
        DropDownList3.DataTextField = "City";
        DropDownList3.DataValueField = "CityId";
        DropDownList3.DataSource = form1;
        DropDownList3.DataBind();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList2.DataSource = obj.ExecuteReader;
        DropDownList2.DataTextField = "State";
        DropDownList2.DataValueField = "StateId";
        DropDownList2.DataSource = form1;
        DropDownList2.DataBind();

    }
protected void  Calendar1_SelectionChanged(object sender, EventArgs e)
{
     TextBox2.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy"); 
}
protected void GridView1_SelectedIndexChanged(object sender, GridViewDeleteEventArgs e)
{
   

            int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); 

                // instantiate BAL

        BusinessLogic pBAL = new BusinessLogic();

        try

        {

            pBAL.Delete();



            Label1.Text  = "Record Deleted Successfully.";

        }

        catch (Exception ee)

        {

            Label1.Text = ee.Message.ToString();

        }

        finally

        {

            pBAL = null;

        }



        GridView1.EditIndex = -1;

        // Refresh the list

        GridView1.DataBind();

    }
}

also in code behind page why
BusinessLogic pBAL = new BusinessLogic();
here businessLogic shows are you missing assembly ref. although i have added refrence in it. Any help will be highly appreciable. Thanks.
Posted
Comments
Rambo_Raja 19-Jun-13 1:00am    
if anyone wants to have a check on my sqlhelperclass i can mail it to him/her.
Rambo_Raja 19-Jun-13 1:02am    
in datalogic using DL; is the namespace in which sqlhelperclass funct. are created

1 solution

Here is a sample project that is using a similar SqlDbhelper class and implementing a 3 tier architecture for a web application. Refer this and I think you will find it very helpful.

Creating ASP.NET Applications with N-Tier Architecture[^]
 
Share this answer
 
Comments
Rambo_Raja 19-Jun-13 1:14am    
hi sir nice to get help from u. but sir i dont want to create connections they are already buit inside the sqlhelperclass i only want to use it. i.e to say i only have to pass parameters from business logic no need to write function for ExecuteNonQuery only have to use it . i have added sqlhelper class in by DAL project but unable to use its functions how can i sir? help me.
Rahul Rajat Singh 19-Jun-13 1:19am    
In the given article if you look at the calls from EmployeeDBAccess to SqlDBHelper you will get an idea how that can be done. You might have to make these calls from one layer up i.e. BLL but the way to do this should be the same. Here is one more complete project that is doing the similar thing that you are trying to do: http://www.codeproject.com/Articles/327764/YaBlogEngine-A-Tiny-Blog-Engine-written-in-ASP-NET [CHECK THE CODE]
Member 12464231 3-Jun-16 2:31am    
Is it possible to use sqlHelper class without stored procedures

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900