Wednesday, 5 March 2014
Connection String:
/b>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
namespace TierLayer
{
public class Connection
{
public static string StrConnSql;//For Sql
public SqlConnection GetConnection()
{
StrConnSql = ConfigurationManager.ConnectionStrings["Con"].ToString();
SqlConnection Connection = new SqlConnection(StrConnSql);
return Connection;
}
}
}
DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace TierLayer
{
public class DataAccessLayer
{
Connection con = new Connection();
public int Insertdate(BusinessProperties Bp)
{
int rows = 0;
SqlConnection conn = new SqlConnection();
conn = con.GetConnection();
SqlCommand cmd = new SqlCommand("tire_demo", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
cmd.Parameters.AddWithValue("@Names", Bp.Name);
cmd.Parameters.AddWithValue("@Mobileno", Bp.Mobileno);
rows = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
rows = 0;
throw ex;
}
finally
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
return rows;
}
}
}
BLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
namespace TierLayer
{
public class BusineeLogic
{
public int Insertdate1(BusinessProperties Bp)
{
DataAccessLayer DL = new DataAccessLayer();
try
{
return DL.Insertdate(Bp);
}
catch (Exception ex)
{
throw ex;
}
}
}
}
BEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TierLayer
{
public class BusinessProperties
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string mobileno;
public string Mobileno
{
get { return mobileno; }
set { mobileno = value; }
}
}
}
User Access Layer
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TierLayer;
namespace _3tier_Arch
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnenter_Click(object sender, EventArgs e)
{
int rowss = 0;
BusinessProperties Bp = new BusinessProperties();
Bp.Name = txtname.Text;
Bp.Mobileno = txtmobile.Text;
BusineeLogic Bl = new BusineeLogic();
rowss= Bl.Insertdate1(Bp);
if (rowss.ToString()=="1")
{
ScriptManager.RegisterStartupScript(btnenter, btnenter.GetType(), "msg", "javascript:alert('Saved Successfully');", true);
}
}
}
}
User Access Layer
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_3tier_Arch._Default" %>
3tier
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment