Thursday 9 September 2021

FAQ--(3- Tier Project)

BACK


 

https://meeraacademy.com/3-tier-architecture-example-in-asp-net-c/

1. Presentation Layer (UI – User Interface Layer)

2. Business Logic Layer (use for write logic code)

3. Data Access Layer (DAL use for connectivity with Database)

 

1)) UI (User Interface) or (Presentation Layer):


 

 

(Default.aspx)  [It is Design inside  invoice_system project]

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

 

<!DOCTYPE html>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Three Tier Architecture in ASP.Net</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<table>

<tr>

<td colspan="2">

3-tier User Registration Form</td>

</tr>

<tr>

<td>

Name :</td>

<td>

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

Address :

</td>

<td>

<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

City :

</td>

<td>

<asp:TextBox ID="txtcity" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

Email :

</td>

<td>

<asp:TextBox ID="txtemail" runat="server" style="height:

22px"></asp:TextBox>

</td>

</tr>

<tr>

<td>

&nbsp;</td>

<td>

<asp:Button ID="Button1" runat="server" Text="INSERT" OnClick ="Button1_Click" />

<br />

<asp:GridView id="gv_display" runat="server"></asp:GridView>

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

 

 

 

 

[Default.cs]

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using DataLayer;

using BusineesLayer;

 

public partial class Default5 : System.Web.UI.Page

{

//Object created of Business Layer class

BLL ObjBLL = new BusineesLayer.BLL();

protected void Page_Load(object sender, EventArgs e)

{

//for select record and bind to gridview

gv_display.DataSource = ObjBLL.GetData();

gv_display.DataBind();

}

 

protected void Button1_Click(object sender, EventArgs e)

{

//////for insert record

ObjBLL.InsertNewUser(txtname.Text, txtaddress.Text, txtcity.Text, txtemail.Text);

 

//////for select record and bind to gridview

gv_display.DataSource = ObjBLL.GetData();

gv_display.DataBind();

}

}

2.) (Business Logic Layer): (Class1.cs)

using DataLayer;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace BusineesLayer

{

public class BLL

{

public DAL objDAL = new DAL();

 

public void InsertNewUser(string _name, string _add, string _city, string _email)

{

objDAL.InsertData(_name, _add, _city, _email);

}

 

public object GetData()

{

return objDAL.SelectData();

}

 

}

}

 

3.) (Data Access Layer): (Class1.cs)

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

 

namespace DataLayer

{

public class DAL

{

public void InsertData(string _name, string _add, string _city, string _email)

{

SqlConnection sqlconn = new SqlConnection

(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

SqlDataAdapter sqladapter = new SqlDataAdapter

("insert into UserMst values

('" + _name + "', '" + _add + "', '" + _city + "', '" + _email + "')", sqlconn);

DataTable DT = new DataTable();

sqladapter.Fill(DT);

 

}

 

//for select record from database below

public object SelectData()

{

SqlConnection sqlconn = new SqlConnection

(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

SqlDataAdapter sqladapter = new SqlDataAdapter("select * from UserMst", sqlconn);

DataTable DT = new DataTable();

sqladapter.Fill(DT);

return DT;

}

}

}

 

 

 

4.))  DataBase And Table Creation  with Stored Procedure

 

CREATE TABLE [dbo].[UserMst] (

[Name]    NVARCHAR (50) NULL,

[Address] NVARCHAR (50) NULL,

[City]    NVARCHAR (50) NULL,

[Email]   NVARCHAR (50) NULL

);





 

STORED PROCEDURE

## For Displaying

CREATE  procedure [dbo].[USERMST_SELECT]

as

begin

/****** Script for SelectTopNRows command from SSMS  ******/

SELECT * FROM UserMst

End

## For Inserting

CREATE PROCEDURE [dbo].[USERMST_INSERT]

 

@NAME AS NVARCHAR(256),

@ADD AS NVARCHAR(256),

@CITY AS NVARCHAR(256),

@EMAIL AS NVARCHAR(256)

AS

BEGIN

 

INSERT INTO USERMST VALUES (@NAME,@ADD,@CITY,@EMAIL)

 

END

 

***** END  END   END    END   END    END **************************************************

 





 

 












2 comments:

  1. Excellent content. It will be beneficial to those who seek information Hire asp.net Developer from Technoduce, we have a team of experienced and expert Asp.net developers, We meet your business requirement on development, customization, designing, migration, maintenance, revamping, etc.

    ReplyDelete

FAQ--(3- Tier Project)

BACK   https://meeraacademy.com/3-tier-architecture-example-in-asp-net-c/ 1. Presentation Layer (UI – User Interface Layer) 2. Busine...