图像保存在数据库中

发布于 2024-08-27 13:53:30 字数 224 浏览 7 评论 0原文

我想将上传的图像保存到数据库中。现在我的问题是:

  1. SQL Server 2000 的图像数据类型应该是什么? 一个。图像 b. varbinary

  2. 将图像保存到数据库的代码是什么?

  3. 如何从数据库中检索图像并显示?

请向我推荐任何教程或指南。或者如果可以请与我分享。

提前致谢。

I want to save an uploaded image to database. Now my question is:

  1. What should be the data type for SQL Server 2000 for image?
    a. image
    b. varbinary

  2. what is the code for saving image in database?

  3. How to retrieve the image from database and show?

Please refer me any tutorial or guidline. Or if you can please share with me.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

假情假意假温柔 2024-09-03 13:53:30

数据类型应该是文本,因为将图像保存到数据库的最佳方法是保存其路径。让您的操作系统完成存储实际文件的工作。

The data type should be text because the best way to save an image to a database is to save its path. Let your OS do the job of storing the actual files.

不忘初心 2024-09-03 13:53:30

通常在 SQL Server 上,您会使用 BLOB(二进制大型对象)来存储图像。我们在之前的项目中将其用于 Word 文档,并且效果很好。请参阅 这篇有关数据库日志的文章了解更多信息,不过快速 Google 一下 BLOB 类型会出现更多示例。

Typically on SQL Server, you would use a BLOB, Binary Large OBject, to store images. We used it for Word documents on a previous project, and it worked just fine. See this article on Database Journal for more info, although a quick Google for the BLOB type will throw up lots more examples.

满身野味 2024-09-03 13:53:30

我写了这篇文章不久前讨论过这个话题。它应该对您的#2 和#3 有帮助。它使用 MySQL,但基本原理是相同的,只需将 MySQL 调用替换为 MSSQL 调用即可。

至于#1,我会选择显而易见的选择:“图像”。
但是,我并不能 100% 确定两者之间的差异。这看起来很明显:)

编辑,根据this,看来 image 数据类型已被弃用。它将在未来版本中删除。鉴于您使用的是 10 年前的版本,不确定这对您有多大影响,但值得记住。

I wrote this article a while back on this subject. It should help you with #2 and #3. It uses MySQL, but the basics are the same, you just need to replace the MySQL calls with the MSSQL calls.

As to #1, I would go with the obvious choice: "image".
I am not 100% sure of the differences between the two, however. It just seems obvious :)

Edit, according to this, it appears that the image datatype is deprecated. It will be removed in future versions. Not sure how much this affects you, seeing as you are using a 10 year old version, but it is worth keeping in mind.

情独悲 2024-09-03 13:53:30

在 SQLServer 中,IMAGE 或 VARBINARY 几乎相同。 IMAGE 为 2GB,但 VARBINARY() 需要长度参数。
将图像存储在数据库中并不是一个好主意,大小会增加很多,每次备份时您都需要保存所有图像,随着大小的增加也会增加执行备份和恢复的时间。您还需要更改网络数据包大小(在服务器属性、高级、网络、网络数据包大小)在最近的 SQLServer 版本中,最精确的数据类型是 varbinary(MAX)

In SQLServer IMAGE or VARBINARY are allmost the same. IMAGE is 2GB but VARBINARY() needs a length argument.
It's not good idea to store images in a database, the size increases a lot, with each Backup you need to save all images, with increasing size also increases the time to perform a Backup and Restore. You also need to change the network packet size (at the server properties, advanced, network, network packet size) In recents SQLServer versions the most adecuate datatype is varbinary(MAX)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文