Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

My problem is that I am working on a website which is giving error on its edit page. When I open to edit a product on edit page and upload a new pic by changing d existing one and enter some description & than click on submit button it is giving "instance of object" error.

However if I do not click the submit button but change the image and verify it in database, the image is changed, but if i use full functionality of my page by changing and editing image and entering or updating some text submission is not successful.

I am sharing my code below

Kindly help !

Thanx in anticipation !!
C#
public partial class admin_Edit_Product : System.Web.UI.Page
{
    SahibImportDataService ds = new SahibImportDataService();
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Visible = false;
        TextBox2.Visible = false;
        TextBox3.Visible = false;
        TextBox4.Visible = false;
        TextBox5.Visible = false;

        if (Convert.ToString(Session["Confirm_move"]) == "1")
        {

            int pm = Convert.ToInt32(Session["PPId"]);
            ImageLoad(pm);

        }
        
        if (!IsPostBack)
        {
            int pm = Convert.ToInt32(Request.QueryString["PId"]);
            ImageLoad(pm);
        }

    }

    private void ImageLoad(int pm)
    {
        Session["PPId"] = pm.ToString();
        add_edit_picture.InnerHtml = " <a href=\"Add_Edit_More Images.aspx?PId=" + pm + "\"  class=\"msgGreen\" target=\"_blank\">Add/Edit Additional Pictures</a>";
        add_edit_picture.InnerHtml = " <a   önclick='javascript: return Add_Edit_LargeImage(" + pm + ");' class=\"msgGreen\" target=\"_blank\">Add/Edit Additional Pictures</a>";
        bind_Product(pm);

        lnkChange.Attributes.Add("onclick", "javascript: return changeImage(" + pm + ");");
        lnkLarge.Attributes.Add("onclick", "javascript: return changeLargeImage(" + pm + ");");
    }
    private void bind_Product(int id)
    {
        string sql = "select * from TBL_Product where  ProductId =" + id;
        SqlDataReader sdr = ds.data_Select(sql);
        if (sdr.Read())
        {
            dd_Category.SelectedValue = sdr.GetInt32(sdr.GetOrdinal("V_Cat_Id")).ToString();
            txtprice.Text = sdr.GetDecimal(sdr.GetOrdinal("Price")).ToString();
            txt_Sprice.Text = sdr.GetDecimal(sdr.GetOrdinal("specialPrice")).ToString();
            txtsplPrice.Text = sdr.GetString(sdr.GetOrdinal("PCode")).ToString();
            
            txtmaterial.Text = sdr.GetString(sdr.GetOrdinal("Material")).ToString();
            txtlen.Text = sdr.GetString(sdr.GetOrdinal("Lenght")).ToString();
            dd_Araival.SelectedValue = sdr.GetString(sdr.GetOrdinal("NArrival")).ToString();
            dd_Clear.SelectedValue = sdr.GetString(sdr.GetOrdinal("Clearance")).ToString();
            TextBox1.Text = sdr["aq"].ToString();
            TextBox2.Text = sdr["bq"].ToString();
            TextBox3.Text = sdr["cq"].ToString();
            TextBox4.Text = sdr["dq"].ToString();
            TextBox5.Text = sdr["eq"].ToString();
            txtShort_Desc.Text = sdr.GetString(sdr.GetOrdinal("Short_Desc")).ToString();
            FCKeditor1.Value = sdr.GetString(sdr.GetOrdinal("Des"));
            Image1.ImageUrl = "../Small-image/" + sdr.GetString(sdr.GetOrdinal("Small_Img"));
            small_Img.Text = sdr.GetString(sdr.GetOrdinal("Small_Img"));

        }
        sdr.Close();


    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        
        try
        {
            if (FCKeditor1.Value == "")
            {
                TD1.InnerHtml = "The Product Desciption Is Required....!!!!";
            }
            else
            {
                //string code = "test";
                //string StrCheckBoxListCollegeType = string.Empty;
                //if (chkcolname.Items.Count > 0)
                //{
                //    for (int i = 0; i < chkcolname.Items.Count; i++)
                //    {
                //        if (chkcolname.Items[i].Selected)
                //        {
                //            StrCheckBoxListCollegeType += chkcolname.Items[i].Value + ",";
                //        }
                //    }
                //}
                int a = 1;
                int b = 1;
                int c = 1;
                int d = 1;
                int eq = 1;
                if (TextBox1.Text != null && TextBox1.Text != "")
                    a = Convert.ToInt32(TextBox1.Text);
                if (TextBox2.Text != null && TextBox2.Text != "")
                    b = Convert.ToInt32(TextBox2.Text);
                if (TextBox3.Text != null && TextBox3.Text != "")
                    c = Convert.ToInt32(TextBox3.Text);
                if (TextBox4.Text != null && TextBox4.Text != "")
                    d = Convert.ToInt32(TextBox4.Text);
                if (TextBox5.Text != null && TextBox5.Text != "")
                    eq = Convert.ToInt32(TextBox5.Text);

                // productid = ds.Insert_And_Update_Product(0, Convert.ToInt32(dd_Category.SelectedValue), Small_name, Convert.ToDecimal(txtprice.Text), txtproCode.Text, txtmaterial.Text, Convert.ToInt32(txtlengt.Text), StrCheckBoxListCollegeType, txtShort_Desc.Text, FCKeditor1.Value.ToString(), Session["User"].ToString(), Session["User"].ToString());

         /*here is my error ->*/       int productid = ds.Insert_And_Update_Product(Convert.ToInt32(Request.QueryString["Pid"].ToString()), Convert.ToInt32(dd_Category.SelectedValue), small_Img.Text, Convert.ToDecimal(txtprice.Text), Convert.ToDecimal(txt_Sprice.Text), txtsplPrice.Text, txtmaterial.Text, txtlen.Text, dd_Araival.SelectedValue, dd_Clear.SelectedValue, txtShort_Desc.Text, FCKeditor1.Value.ToString(), Session["User"].ToString(), Session["User"].ToString(), a, b, c, d, eq);
                string sql = "UPDATE TBL_Product SET color_qty=" + ddl_color.SelectedValue + " WHERE ProductId=" + productid;
                int check = ds.dataInsertResult(sql); 
           
                //Response.Redirect("ViewAll_Product.aspx?msg=edit");
                Response.Redirect("ViewAll_Product.aspx");
            }
        }
        catch (SqlException ex)
        {
            TD1.InnerHtml = ex.Message;
        }
    }
Posted
Updated 16-Feb-12 21:47pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900