3 tier architecture

Posted by Teena12345 under ASP.NET on 11/28/2007 | Views : 2103 | Status : [Member] | Replies : 7
hello everbody,
can u plz give me simple application sample code in 3 tier architecture,plz give me code example to appl'n. create 3 layers of code.




Responses

Posted by: Bubbly on: 2/18/2010 [Member] Bronze

Up
0
Down
Hello,

check this link

http://www.dotnetspider.com/projects/811-Tier-Architecture-ASP-NET.aspx

++
Thanks & Regards,
Deepika

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this

http://www.dotnetfunda.com/articles/article71.aspx


Mark as Answer if its helpful to you

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
3 Tier architecture have 3 layers

1.Presentation Layer
2.Buisness Layer
3.Data access Layer

//Data Layer

static class DAL
{
const string ConnectionString = "server=.;initial catalog=Employee;user id=sa;password=sa123";

public static int ExecuteNonQuery(string commandText, SqlParameter[] parameters)
{
try
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
foreach (SqlParameter param in parameters)
cmd.Parameters.Add(param);

int rowsAffected = cmd.ExecuteNonQuery();

return rowsAffected;
}
}
}
catch
{
throw;
}
}

public static SqlDataReader GetReader(string commandText, SqlParameter[] parameters)
{
try
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(commandText, conn))
{
foreach (SqlParameter param in parameters)
cmd.Parameters.Add(param);

SqlDataReader reader = cmd.ExecuteReader();

return reader;
}
}
}
catch
{
throw;
}
}
}

To resemble the table EmployeeDetails I have created the following entity class

class EmployeeEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }

public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("Employee Name = ").Append(this.Name);
sb.Append(" Have Id = ").Append(this.Id);
sb.Append(" Lives In = ").Append(this.Address);

return sb.ToString();
}
}

//Buisness Layer

static class Employee
{
public static int AddEmployee(EmployeeEntity e)
{
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@Id", e.Id);
param[1] = new SqlParameter("@Name", e.Name);
param[2] = new SqlParameter("@Address", e.Address);

return DAL.ExecuteNonQuery("INSERT INTO EmployeeDetails VALUES(@Id, @Name, @Address)", param);
}

public static EmployeeEntity GetEmployee(int id)
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Id", id);

SqlDataReader reader = DAL.GetReader("SELECT * FROM EmployeeDetails WHERE Id = @Id", param);

if (reader.HasRows)
{
EmployeeEntity emp = new EmployeeEntity();
while (reader.Read())
{
int temp = 0;
int.TryParse(reader["Id"].ToString(), out temp);
emp.Id = temp;
emp.Name = reader["Name"].ToString();
emp.Address = reader["Address"].ToString();

break;
}
return emp;

}
else
return null;
}
}


//presentation Layer

class Program
{
static void Main(string[] args)
{
Employee.AddEmployee(new EmployeeEntity() { Id = 1, Name = "Amal", Address = "MyAddress" });
Employee.AddEmployee(new EmployeeEntity() { Id = 2, Name = "Hashim", Address = "Hashim Address" });
Employee.AddEmployee(new EmployeeEntity() { Id = 3, Name = "Rooney", Address = "Manchester" });

EmployeeEntity emp = Employee.GetEmployee(1);

Console.WriteLine(emp);
}
}

Thanks & Regards
Hari

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/29/2012 [Member] Starter | Points: 25

Up
0
Down
Please Mark As Answer if it is helpful to you

Thanks & Regards
Hari

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 11/28/2007 [Member] Starter

Up
0
Down
Just see if this is what you are looking for.

http://www.dotnetfunda.com/articles/article18.aspx

Regards,
Raja, USA

Teena12345, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 4/18/2009 [Member] Bronze

Login to post response