How to use fileupload control to upload an image and save it in a table in MySQL workbench database? and how to create the connection. the name of tabel is invoicesfp
public partial class Invoices : System.Web.UI.Page
{
MySql.Data.MySqlClient.MySqlConnection conn ;
MySql.Data.MySqlClient.MySqlCommand cmd;
String querystr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
//save image into database
string str = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + "//Invoices//" + str);
string path = "~//Invoices//" + str.ToString();
MySqlConnection conn = new MySqlConnection("Server=127.0.0.1;Database=admindb;Uid=root;Pwd=8888;");
MySqlCommand cmd = new MySqlCommand("insert into invoicesfp values (@v1)", conn);
conn.Open();
cmd.Parameters.AddWithValue("v1", TextBox1.Text);
cmd.ExecuteNonQuery();
conn.Close();
Label4.Text = "Image uploaded sucessfully";
}
else
{
Label4.Text = " Please, upload the image ";
}
}
}