如何使用图片框使用 vb.net 在 sql server 数据库中存储和检索图像 [英] How to store and retrieve images in sql server database with vb.net using picturebox

查看:36
本文介绍了如何使用图片框使用 vb.net 在 sql server 数据库中存储和检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我使用 vb.net 在 SQL Server 数据库中存储和检索图像的最简单技术.

Can someone please tell me the easiest technique to store and retrieve image in a SQL Server database with vb.net.

一个非常重要的考虑要求:

A very important consideration requirement:

嗯,vb.net 中的应用程序似乎有一个可供 LAN 计算机访问的数据库,因此一旦其他计算机应用程序从服务器请求数据库,SQL Server 2005 数据库就允许远程计算机共享其数据库.

Well, the application in vb.net seems to have a database which can accessed by the LAN computers so the SQL Server 2005 database allows remote computers to share its database once the other computer application requests database from the server.

因此,其他每台计算机都必须在 SQL Server 2005 中存储和检索图像.例如,comp1 必须像 tableadapter 一样存储拍摄到服务器中的图像并检索它.

So, every other computer has to store and retrieve images in SQL Server 2005. For example, comp1 has to store images taken into the server and retrieve it like tableadapter.

我正在使用绑定和表适配器将详细信息存储在数据库中并从数据库中检索信息.请如果您有代码或任何对我有用的东西,请在此处发布...

I am using bindings and tableadapters to store the details in database and retrieving information from db. Please if you have code or anything which is working for me, please post it here...

如果有局域网计算机也共享 SQL Server 数据库,请与我分享如何通过 vb.net 存储和检索 SQL Server 图像.

Please share with me how to store image and retrieve it SQL Server through vb.net provided there's LAN computers who are also sharing the SQL Server database.

拜托,如果有人了解这方面的知识,我将不胜感激.

Please, if anyone has a knowledge about this stuff, I would really appreciate it.

我全心全意地请求您考虑我的问题.

With all my heart, I request you consider my issue, please.

此致,

侯赛因

推荐答案

让我们有一个包含图像的表格(而不是 max 你可以使用所需的大小):

Let's have a table containing images (instead of max you can use desired size):

CREATE TABLE dbo.STORED_IMAGES
     (
     ID int NOT NULL  IDENTITY (1, 1),
     Img varbinary(MAX) NULL
     ) 

存储图像:

Dim CMD As New SqlClient.SqlCommand("insert into STORED_IMAGES(Img) values(@Img)",cn)
CMD.Parameters.Add("@Img", SqlDbType.VarBinary, Integer.MaxValue).Value = ReadFile(Path)

读取文件功能:

Private Function ReadFile(sPath As String) As Byte()
        Dim data As Byte() = Nothing
        Dim fInfo As New IO.FileInfo(sPath)
        Dim numBytes As Long = fInfo.Length
        Using fStream As New IO.FileStream(sPath, IO.FileMode.Open, IO.FileAccess.Read)
            Dim br As New IO.BinaryReader(fStream)
            data = br.ReadBytes(CInt(numBytes))
        End Using
        Return data
    End Function

从数据库获取文件:

Dim fcmd As New SqlCommand("select Img from STORED_IMAGES where ID=@ID", cn)
fcmd.Parameters.Add("@ID", SqlDbType.Int).Value = 3 'e.g.
Dim bytes As Byte() = fcmd.ExecuteScalar

我想使用 tableadapters,您的数据表将包含类型为 Byte() 的列.

I suppose that with tableadapters your datatable will contain column with type Byte().

这篇关于如何使用图片框使用 vb.net 在 sql server 数据库中存储和检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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