This code snippet is used to show the difference between Insert and update mechanisms in layered architecture and without layered architecture
protected void btn_save_Click(object sender, EventArgs e)
{
try
{
employeeName = txt_name.Text;
designation = txt_designation.Text;
address = txt_add.Text;
phoneNumber = Convert.ToInt32(txt_ph.Text);
fun_insert(employeeName, designation, phoneNumber, address);
lbl_status.Text = "Records saved";
}
catch (Exception ex)
{
lbl_status.Text = ex.Message;
}
finally
{
}
}
private void fun_insert(string empname, string designation, long phno, string address)
{
try
{
mycon.Open();
cmd = new SqlCommand("sp_empdetails2", mycon);
cmd.Parameters.AddWithValue("@empname", empname);
cmd.Parameters.AddWithValue("@designation", designation);
cmd.Parameters.AddWithValue("@phno", phno);
cmd.Parameters.AddWithValue("@addr", address);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lbl_status.Text = ex.Message;
}
finally
{
mycon.Close();
}
}
In Layered Architectures
protected void radbtnSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
valuesetParameter = new ValuesetParameter(); //Entity Class
valuesetParameter.ValueSetId = Convert.ToInt32(Session["ValuesetID"]);
valuesetParameter.Name=radtxtParameterName.Text;
//valuesetParameter.StatusName = StatusType.Active;
valuesetParameter.Behavior = radtxtBehaviourName.Text;
valuesetParameter.DisplayOrder = 2;
valuesetParameter.CreatedBy = 1;
valuesetParameter.CreatedIP = GetLocalIPAddress();
genealSetupProcess.CreateValuesetParameter(valuesetParameter);
}
}

Join the conversation! Your thoughts help the community grow.