在MS Access和SQL Server中处理图片 [英] Working with pictures in MS Access and SQL Server

查看:143
本文介绍了在MS Access和SQL Server中处理图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

究竟是怎么回事:


  1. 将图片/图片放入SQL数据库

  2. 使用MS Access表单从SQL数据库查看图片?

我目前在两个数据库之间使用ODBC链接,没有任何问题所有,但我很难理解我需要做些什么来实现我想要实现的目标。

我已经尝试过Google,但还没有找到正确的信息。

解决方案

将图片输入和输出SQL Server数据库:



你需要 GetChunk AppendChunk 函数。

这是一个教程:如何使用GetChunk和AppendChunk读取和写入BLOB 。$
本教程有点陈旧,但据我所知,这仍然是加载/保存图片的最佳方式。来自VBA的数据库。

请注意,在SQL Server中,您应该使用 varbinary(max)字段(而不是图像在教程中建议)存储图片。



以MS Access形式显示图片:



您无法直接从数据库中显示图片。您必须从数据库(见上文)加载它,将其存储在临时文件夹中并从那里显示它。



要获取Windows的临时文件夹,请使用 Environ(temp) GetTempPath API函数



要显示图片,您可以将其设置为表单的背景:

  Me.Picture =c:\。 ..\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ / p> 

  Me.NameOfImageControl.Picture =c:\ ... \ temp\picture.jpg


How exactly does one go about:

  1. getting images/pictures into a SQL database
  2. viewing pictures from a SQL database using a MS Access form?

I currently use an ODBC link between the two databases with no problems at all, but I'm struggling to understand what I need to do to achieve what I'm trying to achieve.
I have already tried Google, but haven't yet come across the right information.

解决方案

Getting pictures in and out of an SQL Server database:

You need the GetChunk and AppendChunk functions for that.
Here's a tutorial: How To Read and Write BLOBs Using GetChunk and AppendChunk.
This tutorial is a bit dated, but as far as I know this is still the best way to load/save pictures in a database from VBA.
Note that in SQL Server, you should use a varbinary(max) field (instead of the image suggested in the tutorial) to store the pictures.

Displaying the pictures in an MS Access form:

You can't display a picture directly from the database. You have to load it from the database (see above), store it in a temp folder and display it from there.

To get Windows' temp folder, use Environ("temp") or the GetTempPath API function.

To display the picture you can either set it as the background of the form:

Me.Picture = "c:\...\temp\picture.jpg"

...or use a image control:

Me.NameOfImageControl.Picture = "c:\...\temp\picture.jpg"

这篇关于在MS Access和SQL Server中处理图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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