I having problem on saving image into my database. I don't know how to insert or store image into my database and display in my gridview.
Here's my design of my table:
In my web method :
[WebMethod(EnableSession = true)]
public string sell_item(string name, Image photo, string description)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=Bidding;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE login SET name = @name, photo = @photo, description = @description WHERE username=@username", con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@photo", photo);
cmd.Parameters.AddWithValue("@description", description);
cmd.ExecuteNonQuery();
con.Close();
return "Product has been upload successfully!";
}
My code in web application which call the web service:
I using FileUpload button to choose my image file.
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(a.sell_item(Convert.ToString(TextBoxName.Text), Convert.ToString(FileUploadPhoto.FileName), Convert.ToString(TextBoxDescription.Text)));
Label1.Visible = true;
if (Label1.Visible == true)
{
MessageBox.Show("Item has been uploaded successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
Response.Redirect("Menu page.aspx");
}
}
In my gridview I have set the properties :
The image wouldn't display in the gridview. I'm still new to c#. Anyone can help me? Thanks.