2011-02-16 152 views
3

我有一個asp頁面。在asp頁面中,我有一個圖像控件。圖像控件中有一個圖像。我想將這個圖像保存在數據庫中。在數據庫中,特定的字段數據類型是圖像。這怎麼可能?在數據庫中存儲圖像

+0

爲什麼你喜歡數據庫而不是文件系統? – 2011-02-16 08:45:31

+0

嘗試接受您的問題的一些答案。這會激勵他人在未來回答你的問題。 – JPReddy 2011-02-17 05:58:47

回答

4

檢查這篇文章出來:

FileUpload img = (FileUpload)imgUpload; 
Byte[] imgByte = null; 
if (img.HasFile && img.PostedFile != null) 
{ 
    //To create a PostedFile 
    HttpPostedFile File = imgUpload.PostedFile; 
    //Create byte Array with file len 
    imgByte = new Byte[File.ContentLength]; 
    //force the control to load data in array 
    File.InputStream.Read(imgByte, 0, File.ContentLength); 
} 

然後使用:從上面的文章

首先你需要將圖像轉換爲字節這樣的 Save and Retrieve Images from the Database using ASP.NET 2.0 and ASP.NET 3.5

imgByte作爲添加到數據庫時的值。

相關問題