且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将图像添加到数据库

更新时间:2023-02-07 11:12:18

假设您使用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