Wednesday 22 February 2012

How can we insert image using file upload control using asp.net

1.Firstly create Table
2.Secondly create store procedure

Then .cs page code below:-

if (FileUpload1.HasFile)
            {
                string productname = txtProductName.Text;
                byte[] productimage = FileUpload1.FileBytes;



                SqlConnection con = new SqlConnection("initial catalog=practise;data source=IICTECH-B337995;integrated security=true;");
                SqlCommand cmd = new SqlCommand("product2", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@prodname", SqlDbType.NVarChar).Value = productname;
                cmd.Parameters.Add("@prodimage", SqlDbType.VarBinary).Value = productimage;
                con.Open();
                int result = cmd.ExecuteNonQuery();
                con.Close();
                if (result > 0)
      {
         lblMessage.Text = "Product Saved Successfully";
      }
   }
   else
   {
      lblMessage.Text = "Please Select Product Image File";
   }
            }
        }

No comments:

Post a Comment