如何将图像存储在数据库中 [英] How to store the image in database

查看:97
本文介绍了如何将图像存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我进行编码以在Visual Studio2010中浏览和保存图像并将图像存储到sql server2008吗?

解决方案

使用此链接
在SQL Server中存储图像 [ 解决方案

Use this link
Store Images in SQL Server[^]


//to convert ur attachment into bytearray
byte[] Attachmnt;
tbUpload.Text = openFileDialog1.SafeFileName;
FilePath = openFileDialog1.FileName;
 if (openFileDialog1.FileName != null)                        
{     
System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
long byteLength = new System.IO.FileInfo(FilePath).Length;
Attachmnt = binaryReader.ReadBytes((Int32)byteLength);
fs.Close();
fs.Dispose();
binaryReader.Close();
}     



 public class Document   
       {      
        public byte[] DocContent { get; set; }
       }
//on the upload event
Document objDoc = new Document();
 objDoc.DocContent = Attachmnt;
ResumeData_ = objDoc.DocContent;
Submit();//my function to save resumedata at database where column type is image
                pre>


You can save the byte array in database. For this you need to convert the image in byte array.


这篇关于如何将图像存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆