|
-
Dec 15th, 2003, 01:47 AM
#1
Thread Starter
Lively Member
n-tiers
Hi All,
I have read in some books about 3-tiers architecture. I know we should seperate the application into tiers (presentation, business logic, data access, and data). Because the presentation does not connect to data access layer directly so in business logic layer, I have to write most methods that I have done on data access layer. Example
=====Data Access=====
/// <summary>
/// gets the name of the project,which has the project id = nProjID
/// </summary>
/// <param name="nProjID"></param>
/// <returns></returns>
public string GetProjectName(int nProjID)
{
string strName;
// Establish Connection
SqlConnection oConnection = GetConnection();
// build the command
SqlCommand oCommand = new SqlCommand("GetProjectName",oConnection);
oCommand.CommandType=CommandType.StoredProcedure;
// Parameters
SqlParameter paraProjID = new SqlParameter("@ProjID",SqlDbType.Int);
paraProjID.Value=nProjID;
oCommand.Parameters.Add(paraProjID);
SqlParameter paraName= new SqlParameter("@Name",SqlDbType.Char,50);
paraName.Direction=ParameterDirection.Output;
oCommand.Parameters.Add(paraName);
try
{
oConnection.Open();
oCommand.ExecuteNonQuery();
strName=(string) paraName.Value;
return strName;
}
catch(Exception oException)
{
throw oException;
}
finally
{
oConnection.Close();
}
}
====Business Logic==============
/// <summary>
///
/// </summary>
/// <param name="nProjID"></param>
/// <returns></returns>
public string GetProjectName(int nProjID)
{
try
{
string strProName;
DAProject oDAProject = new DAProject();
strProName=oDAProject.GetProjectName(nProjID);
return strProName;
}
catch(Exception oException)
{
throw oException;
}
}
=============================
Could you please tell me why don't we connect directly to Data Access layer? just have some methods that need to implement a business rule. We only use business logic class on this case? is it good?
Thanks in advance,
Trung Luu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|