将图像存储在数据库中 [英] Storing Images in database

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

问题描述

我可以直接将图像存储在数据库中吗?

我不想从代码中插入它.

有可能吗?

Can I directly store images in a database.

I don''t want to insert it from code.

Is it possible ?

推荐答案

您可以这样做:

you can do this way:

CREATE TABLE myTable(Document varbinary(max))
INSERT INTO myTable(Document)
SELECT * FROM
OPENROWSET(BULK N'C:\Image1.jpg', SINGLE_BLOB)



如果要插入多个图像,请执行以下操作:



if you want to insert multiple images do something like this:

DECLARE @imgString varchar(80)
DECLARE @insertString varchar(3000)

SET @imgNumber = 1
WHILE @imgNumber < 101
BEGIN
SET @imgString = 'E:\images\Picture' + CONVERT(varchar,@imgNumber) + '.jpg'
SET @insertString = N'INSERT INTO images(imageData)
SELECT * FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg'
EXEC(@insertString)
SET @imgNumber = @imgNumber + 1
END
GO



希望这会有所帮助:)



hope this helps :)



通过将图像读取为二进制数据,然后将其保存到BLOB结构中来完成将图像存储在数据库中的操作.您可以在网上找到许多与此主题相关的示例:
例如
存储和保存图像 [在SQL Server中存储或保存图像 [图像和SQL Server [
Hi,
storing an image in a database is done by reading it as a binary data, and then saving it into the BLOB structure. You can find lots of examples on the web regarding this topic:
E.g.
Store and save image[^]
Store or Save images in SQL Server[^]
Images and SQL Server[^]
Regards


只是其他的补充: C#相册查看器 [ ^ ]
Just an addition to others: C# Photo Album Viewer[^]


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

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