I have created a table in sql database with some columns.In that one column name is 'Featured' with char (1) and default value is 'N'.While filling form in aspx page, if i didn't checked 'Featured' checkbox, in database in saving as 'N', but if i check that 'Featured' checkbox, the database column should save as 'Y'.Can any one help me with this?
What I have tried:
DAL:
public void save_Click(int pid, string pname,bool fea, string sdesc)
{
SqlCommand cmd = new SqlCommand("SPSAVEDATA", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@P_id", pid);
cmd.Parameters.AddWithValue("@P_name", pname);
cmd.Parameters.AddWithValue("@P_isfeatured", fea);
cmd.Parameters.AddWithValue("@P_shortdesc", sdesc);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
BAL:
public void Product(int pid, string pname,bool fea, string sdesC)
{
dll.save_Click(pid, pname,fea, sdesc);
}
CS:
protected void Btn_save_Click(object sender, EventArgs e)
{
if (HiddenField1.Value == "")
{
bll.Product(0, txt_proName.Text, Convert.ToBoolean(chk_featured.Checked), txt_sdesc.Text);
Response.Write("<script>alert('Product Added Successfully')</script>");
}
else
{
bll.Product(Convert.ToInt16(HiddenField1.Value), txt_proName.Text,Convert.ToBoolean(chk_featured.Checked), txt_sdesc.Text);
Response.Write("<script>alert('Product Updated Successfully')</script>");
}
}
Stored Procedure:
ALTER PROC [dbo].[SPSAVEDATA]
@P_id int,
@P_name varchar(50),
@P_isfeatured char(1),
@P_shortdesc varchar(150)
AS
BEGIN
if(@P_id = 0)
BEGIN
insert into Products1 (P_name,P_isfeatured,P_shortdesc) values (@P_name,@P_isfeatured,@P_shortdesc)
END
else
BEGIN
update Products1 set P_name=@P_name,P_isfeatured=@P_isfeatured,P_shortdesc=@P_shortdesc where P_id=@P_id
END
END