2011-02-16 165 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作为添加到数据库时的值。