如何在visual studio 2012中使用c#在Mysql数据库中插入图像? 我使用了这段代码,但它有问题,我不知道它是什么? 另外,我应该在这段代码中放在括号内:
cmd.Parameters.Add(); to save the value as an image.
public partial class Invoices : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection("server=localhost; userid=root; password=""; database=admindb; allowuservariables=True");
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "insert into tablename(invoicesfp) VALUES (@val1)";
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.Add("val1");
connection.Open();
cmd.BeginExecuteNonQuery();
connection.Close();
#region fileupload
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string ret = ChangeName();
string SaveLocation = Server.MapPath("Invoices") + "\\" + ret;
try
{
FileUpload1.PostedFile.SaveAs(SaveLocation);
}
catch (Exception ex)
{
if (ex is ArgumentNullException || ex is NullReferenceException)
{
throw ex;
}
}
string PicAddress = "~/Invoices/" + ret;
#endregion
}
public static string ChangeName()
{
return Guid.NewGuid().ToString("N") + ".jpg";
}
}