Pages

Thursday, 2 February 2012

Updating the Record

protected void  imgbtnUpdate_Click(object sender, ImageClickEventArgs e)
{
    if (imgFileUpload.HasFile)
    {
        string fileExt = Path.GetExtension(imgFileUpload.PostedFile.FileName);
        if (fileExt.ToLower() == ".jpeg" || fileExt.ToLower() == ".jpg" || fileExt.ToLower() == "gif" || fileExt.ToLower() == ".png")
        {
            try
            {
                string s = @"~\images\EventsImages\" + imgFileUpload.FileName;
                imgFileUpload.PostedFile.SaveAs(Server.MapPath(s));
                SqlCommand cmd = new SqlCommand("UpdateServices", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter  p1 = new SqlParameter("@pImageService", SqlDbType.VarChar);
                p1.Value = s.ToString();
                cmd.Parameters.Add(p1);
                p1 = new SqlParameter("@pSno", SqlDbType.Int);
                p1.Value = Convert.ToInt32(Session["Sno"].ToString());
                cmd.Parameters.Add(p1);
                p1 = new SqlParameter("@pContentService", SqlDbType.VarChar);
                p1.Value = Editor1.Content;
                cmd.Parameters.Add(p1);
                p1 = new SqlParameter("@pTitleService", SqlDbType.VarChar);
                p1.Value = txtTitle.Text;
                cmd.Parameters.Add(p1);
                con.Open();
                cmd.ExecuteNonQuery();


                lblstatus.Text = "<script>" + Environment.NewLine + "alert('Advertisment Posted Successfully')</script>";

                GetServiceName();
                con.Close();
                imgbtnAdd.Visible = true;
                imgbtnUpdate.Visible = false;
                panel1.Visible = false;
                panel2.Visible = true;
            }

            catch (Exception ex)
            {
                lblMessage.Text = "<script>" + Environment.NewLine + "alert('Advertisment Can Not Be Added')</script>";


            }
        }
    }
    else
    {
        SqlCommand cmd = new SqlCommand("UpdateServices", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter p1 = new SqlParameter("@pImageService", SqlDbType.VarChar);
        p1.Value = Session["ImageService"].ToString();
        cmd.Parameters.Add(p1);
        p1 = new SqlParameter("@pSno", SqlDbType.Int);
        p1.Value = Convert.ToInt32(Session["Sno"].ToString());
        cmd.Parameters.Add(p1);
        p1 = new SqlParameter("@pContentService", SqlDbType.VarChar);
        p1.Value = Editor1.Content;
        cmd.Parameters.Add(p1);
        p1 = new SqlParameter("@pTitleService", SqlDbType.VarChar);
        p1.Value = txtTitle.Text;
        //p1.Value = Session["TitleService"].ToString();
        cmd.Parameters.Add(p1);
        con.Open();
        cmd.ExecuteNonQuery();
       
        lblstatus.Text = "<script>" + Environment.NewLine + "alert('Advertisment Posted Successfully')</script>";

        GetServiceName();
        con.Close();
        imgbtnAdd.Visible = true;
        imgbtnUpdate.Visible = false;
        panel1.Visible = false;
        panel2.Visible = true;
    }
}

No comments:

Post a Comment