Click here to Skip to main content
16,012,025 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello sir i user three tier Architecture and what is the code of insert data in sql server 2008 database


quick reply to me thanks
Posted

3-Tier architecture is a very well know buzz word in the world of software development whether it web based or desktop based.
3-Tier Architecture in ASP.NET with C#[^]
Building a 3-Tier Application using ASP.NET
[^]

3-tier application is a program which is organized into three major disjunctive tiers on layers. Here you can see that how these layers increase the reusability of codes.
Three Tier Architecture in ASP.NET[^]

A CP article on the background, advantages and usage of 3-tier architectures in C#.
3-tier architecture in C#[^]

Detailed explanation:
3-Tier Architecture in asp.net using c#[^]

Some more:
3-tier architecture in C#[^]
3-Tier Architecture Examples[^]
3-Tier Architecture in ASP.NET with C#[^]
 
Share this answer
 
Suppose you are working with three tier Architecture then just create Two Class file as like Class1.cs and Class2.cs first one Class1.cs contains with Properties of table as like:


Code in Class1.cs

namespace _class1 //also create namespace
{
public class Class1
{
public Class1()
{

}

//create a properties as your table have field
public int Id { get; set; }
public string name { get; set; }
}
}


now write coed in Class2.cs
first declare namespace and used namespace of properties declaration class file:

using System.Data.SqlClient;
using _class1;

namespace _class2
{
public class Class2
{
Class1 c1 = new Class1();
public Class2()
{

}

public void InsertData()
{
SqlConnection cnn = new SqlConnection("Data Source=hoth;Initial Catalog=Chintan;User ID=sa");
cnn.Open();
SqlCommand cmd = new SqlCommand("Insert into tbl_data values(@name)",cnn);
cmd.Parameters.AddWithValue("@name",c1.name); //c1.name access from property class file
cmd.ExecuteNonQuery();
cnn.Close();
}
}
}


Now create object of both class file in code behind file as below given code:

namespace _class1;
namespace _class2;

public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
Class1 c1 = new Class1();
Class2 c2 = new Class2();

c1.name = txtname.text;

c2.InsertData(c1);

lblmessage.text = "Record Inserted Successfully....!!!";
}
}


I hope its helpful to you
 
Share this answer
 
Example:

bal_Attendance obj = new bal_Attendance(); //public//

button()
{

C#
obj.branch_id = int.Parse(ddlbranch.SelectedItem.Value);
                   obj.date = dt.ToShortDateString();
                   obj.attendance = status.ToString();
                   obj.employee_id = int.Parse(e_id.Text);
                   obj.employeename = e_name.Text;



}
 
Share this answer
 
Comments
Thanks7872 15-Jun-13 6:23am    
how is data going into database in above code?

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