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..
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.
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