Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am trying to figure out problem in it from the last four hour.. i have a problem in saving image to database..

few days ago i just tested that code for uploading images to db and it is working fine..

C#
protected void uploadbtn_Click(object sender, EventArgs e)
   {
       string path = Server.MapPath(".") + "\\images\\" + FileUpload1.FileName;
       FileUpload1.SaveAs(path);
       SqlConnection con = new SqlConnection();
       con.ConnectionString = connectionString;
       string query="insert into photos(filename) values('"+FileUpload1.FileName+"')";
       SqlCommand cmd = new SqlCommand(query, con);
       con.Open();
       cmd.ExecuteNonQuery();
       con.Close();
       Response.Redirect(Request.Url.AbsoluteUri);


now i am trying to implement it in other project.. and suprisingly the FileUpload1.filename is passing empty string. i don't know y. here is the code for on which i am implementing the same code as above. but not working for me. it leaves the image path column empty in productimage field in the database.

C#
 try
        {
            string path = Server.MapPath(".") + "\\Images\\" + FileUpload1.FileName;
            FileUpload1.SaveAs(path);
            SqlConnection con = new SqlConnection();
            con.ConnectionString = connectionString;
SqlCommand cmd = new SqlCommand();
            cmd = con.CreateCommand();
            
            cmd.CommandText="insert into ESK_Products(CategoryID,ProductName,ProductImage,UnitCost,Description)select CategoryID,' + " + txtproname.Text + "','" + FileUpload1.FileName + "'," + txtproprice.Text + ",'" + txtprodesc.Text + "' from ESK_Categories where CategoryName='" + DropDownList1.Text + "'";
            cmd.ExecuteNonQuery();
            lblresult.Text = "inserted";
            con.Close();


i am trying to figure that out from the last 4hours but not able to reslove it
Posted

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