我在ASP.NET C#中創建了一個應用程序,並且想要使用ASP:FileUpload工具將圖像上載到MySQL(二進制字段)。我只能編寫以下代碼,而其他代碼則無法理解。我一整天都在Google上搜索,找不到任何相關信息。任何幫助!在C#中將圖像上傳到數據庫中
ASPX文件
<asp:FileUpload ID="FileUpload1" runat="server" />
br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
C#文件
protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile fup = FileUpload1.PostedFile;
cmd = new OdbcCommand("INSERT into profile(picture) VALUES(?)", MyConnection);
cmd.Parameters.Add("@picture", OdbcType.Binary) = fup;
MyConnection.Open();
cmd.ExecuteNonQuery();
MyConnection.Close();
}
[插入圖像到mysql數據庫使用fileupload控件]可能的重複(http://stackoverflow.com/questions/5724505/inserting-an-image-into-mysql-database-using-fileupload-control) – M4N 2012-01-09 14:10:35