Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Friday, April 24, 2009

Insert record in database using 3-Tier Architecture asp.net

Insert data in database using 3 Tier Architecture .
In this article i am explaining you how to insert record in database using 3-Tier Architecture.You can create separate project for Business and data access layer or also can keep in App_code folder.

This is aspx.cs code.Here code communicate through Business Layer.

protected void btnSubmit_Click(object sender, EventArgs e)
{
objClientCls.ClName = txtCoName.Text;
objClientCls.AddLine1 = txtAddLine1.Text;
objClientCls.AddLine2 = txtAddLine2.Text;
try
{
if (objClientCls.ClId == 0)
{
string Msg = objClBLL.InsertClMaster(objClientCls);
lblMessage.Text = Msg;
Clear();
}
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
finally
{
objClBLL = null;
}
}

Business Layer Code

public string InsertClMaster(ClMasterCls objClMasterCls)
{
try
{
return objClMasterDAL.Insert(objClMasterCls);
}
catch
{
throw;
}
finally
{
objClMasterDAL = null;
}
}

Data Acess layer code
public string Insert(ClMasterCls objClMasterCls)
{
try
{
conn.Open();
string CreateMsg = Convert.ToString(SqlHelper.ExecuteScalar(conn, "usp_InsertClMaster", objClMasterCls.ClId, objClMasterCls.ClName, objClMasterCls.AddLine1
, objClMasterCls.AddLine2));
return Msg;
}
catch
{
throw;
}
finally
{
conn.Close();
}
}

Thanks & Regards
Santosh Singh

No comments:

Post a Comment