sql-server - 如何通过VB.NET在sql server数据库中存储和检索图像

标签 sql-server database vb.net

SQL Server 支持客户端存储的能力 表中的对象。

创建数据类型为 Image 的 Field,并初始化为空值的字节数组。使用 FileInfo 对象获取文件大小。打开 FileStream 读取文件。使用

最佳答案

在此处发帖之前先用谷歌搜索一下。以下是我针对您的查询得到的第三个搜索结果。我知道该怎么做,但没有足够的耐心再做一次。这是来自 TechArena 的示例代码

Function SaveImage _
   (ByVal FileName As String) As Integer

   ' Create a FileInfo instance
   ' to retrieve the files information
   Dim fi As New FileInfo(FileName)

   ' Open the Image file for Read
   Dim imgStream As Stream = _
      fi.OpenRead

   ' Create a Byte array the size
   ' of the image file for the Read
   ' methods buffer() byte array
   Dim imgData(imgStream.Length) As Byte
   imgStream.Read(imgData, 0, fi.Length)

   Dim cn As New SqlConnection _
      (ConfigurationSettings.AppSettings("cn"))
   Dim cmd As New SqlCommand("Images_ins", cn)
   cmd.CommandType = CommandType.StoredProcedure

   With cmd.Parameters
      .Add("@FileName", VarChar, 100).Value = _
         fi.Name
      .Add("@FileType", VarChar, 10).Value = +
         fi.Extension
      .Add("@Image", Image).Value = imgData
      .Add("@FileSize", Int, 4).Value = fi.Length
   End With

   cn.Open()
   cmd.ExecuteNonQuery()
   cn.Close()
   cn.Dispose()
End Function

关于sql-server - 如何通过VB.NET在sql server数据库中存储和检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1397708/

相关文章:

javascript - 如何让webbrowser控件内的网页触发windows窗体的vb.net功能?

sql-server - SQL Server SELECT 嵌套

php - 检查用户id是否已经存在于Mysql数据库中

使用 PhoneGap 的 Javascript 数据存储解决方案

database - Postgres - 如何将更改从开发数据库部署到实时版本

.net - 远程控制/调试 .NET 应用程序的最佳方法是什么?

c# - 非泛型类是否可能包含 .NET(C# 或 VB.NET)中的泛型列表?

sql-server - NVarchar(max) 到 XML 解析错误

c# - SqlFileStream - 插入而不产生空文件

sql - 如何在此 SQL Pivot 查询中插入 TOTAL 列?