Example #1
0
        protected void Upload_Click(object sender, EventArgs e)
        {
            Store.Data.MyDataEntities dc = new Store.Data.MyDataEntities();
            if (ProductImageUpload.HasFile)
            {
                try
                {
                    //Creation of the address string that is stored and is used to access the image's location
                    string q       = Request.QueryString["ProductID"];
                    string imgName = Path.GetFileName(ProductImageUpload.FileName);
                    ProductImageUpload.SaveAs(Server.MapPath("~/ProductImages/") + imgName);

                    imgName = "~/ProductImages/" + imgName;

                    //Set the Product's ImageFile to the image address string
                    dc.Database.ExecuteSqlCommand("UPDATE Product SET ImageFile = {0} WHERE(ProductID = {1})", imgName, q);

                    //Rebind the GridView and DataView to reflect changes to items
                    PADGrid.DataBind();
                    PADDetails.DataBind();
                }
                catch (Exception ex)
                {
                    //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
Example #2
0
    protected void btninsert_Click(object sender, EventArgs e)
    {
        try{
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;

            con.Open();


            SqlCommand cmd = new SqlCommand();
            cmd.Connection  = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_insert_product";
            cmd.Parameters.AddWithValue("@productname", txtProductname.Text);

            if (ProductImageUpload.HasFile)
            {
                if (checkextension(ProductImageUpload.FileName))
                {
                    if (ProductImageUpload.PostedFile.ContentLength < 1000000)
                    {
                        string path = Server.MapPath("Product_Image");
                        path = path + "\\" + ProductImageUpload.FileName;

                        ProductImageUpload.SaveAs(path);
                        cmd.Parameters.AddWithValue("@productimage", "~\\Product_Image\\" + ProductImageUpload.FileName);
                    }
                }
            }

            cmd.Parameters.AddWithValue("@productprice", txtproductprice.Text);
            cmd.Parameters.AddWithValue("@productdisprice", txtproductdisprice.Text);
            cmd.Parameters.AddWithValue("@productsize", txtproductsize.Text);
            cmd.Parameters.AddWithValue("@productbrand", txtproductbrand.Text);
            cmd.Parameters.AddWithValue("@productcolour", txtproductcolour.Text);
            cmd.Parameters.AddWithValue("@productdiscount", txtproductdiscount.Text);



            int result = cmd.ExecuteNonQuery();

            if (result > 0)
            {
                Response.Write("<script>alert('insert successfully')</script>");
            }

            con.Close();
            txtProductname.Text     = string.Empty;
            txtproductprice.Text    = string.Empty;
            txtproductdisprice.Text = string.Empty;
            txtproductsize.Text     = string.Empty;
            txtproductbrand.Text    = string.Empty;
            txtproductcolour.Text   = string.Empty;
            txtproductdiscount.Text = string.Empty;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('Error Occured Please Contact to Admin')</script>");
        }
    }