使用sql helper类(在3层ASP.net中)应用程序实现业务逻辑层 [英] implementing business logic layer using sql helper class(in 3-tier ASP.net) application

查看:90
本文介绍了使用sql helper类(在3层ASP.net中)应用程序实现业务逻辑层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....

我想在我的3层架构中使用sqlhelperclass。项目。我的公司使用sqlhelper类,不使用DAL。所以我的问题是如何在DAL中使用sqlhelperclass。我的老板说我没有按照他们的要求工作。我如何在下面的代码中使用sqlhelperclass并制作我的小项目。 BAL中的
代码:

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:

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;

            }

        }

    }

}



还使用System.Data在DAL中编码:


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();

这里businessLogic显示你缺少程序集引用。虽然我在其中加入了参考。任何帮助都会非常值得一提。谢谢。

here businessLogic shows are you missing assembly ref. although i have added refrence in it. Any help will be highly appreciable. Thanks.

推荐答案

这是一个示例项目,它使用类似的SqlDbhelper类并为Web应用程序实现3层架构。请参阅此内容,我认为您会发现它非常有用。



使用N层体系结构创建ASP.NET应用程序 [ ^ ]
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[^]


这篇关于使用sql helper类(在3层ASP.net中)应用程序实现业务逻辑层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆