将图像添加到数据库 [英] Adding images to database

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

问题描述

我需要在我的数据库表中添加一些图像。我该怎么做(如何将图像转换为二进制)。给我一个示例的答案。使用一个小示例应用程序。

I need to add some images to my database table.How can I do that(How to convert images into binary). Give me an answer with an example.with a small example application.

推荐答案

假设您使用SQL Server作为数据库,这里有一些可能对您有帮助的链接。

你可以使用图片栏。



试试

使用标记过程从SQL Server存储和检索图像C#.net [ ^ ]

在SQL Server中存储或保存图像 [ ^ ]

HTT p://www.mindstick.com/Blog/184/Save%20image%20in%20SqlServer%20usin [ ^ ]
Assuming you are using SQL Server as the database, here are some links that might help you.
You can use the image column.

Try
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]
Store or Save images in SQL Server[^]
http://www.mindstick.com/Blog/184/Save%20image%20in%20SqlServer%20usin[^]


要添加到Abhinav的答案,如果你想使用图像的FileStream,看看如何将二进制数据存储和提取到文件流列 [ ^ ]
To add to Abhinav''s answer, if you want to use FileStream for the images, have a look at How to store and fetch binary data into a file stream column[^]


亲爱的Nishantha,



我希望您使用SQL Server来存储图像。这是我在项目中用于将配置文件图片插入数据库的代码。



Dear Nishantha,

I hope that you are using SQL Server to store the images. Here is the code that I use in my project to insert profile pictures to the Database.

string FileName = "";
Byte[] img = new byte[0];

FileDialog filedialog = new OpenFileDialog();
filedialog.ShowDialog();
FileName = filedialog.FileName;
yourPictureBox.ImageLocation = FileName;

if (FileName.Length > 0)
{
    FileStream fs = new FileStream(FileName, FileMode.Open);
    img = new Byte[fs.Length];
    fs.Read(img, 0, (int)fs.Length);
    fs.Close();
}





Kushan Randima

软件工程师

DigiteQ Solutions PVT LTD



Kushan Randima
Software Engineer
DigiteQ Solutions PVT LTD


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

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