【问题标题】:VB.NET retrieving varbinary data into picture boxVB.NET 将 varbinary 数据检索到图片框中
【发布时间】:2014-08-12 11:32:09
【问题描述】:

我在 SQL Server 的 VARBINARY 列中有一些数据,我只想知道如何在 VB.NET 中将其显示到 PictureBox 中。如何做到这一点?

二进制数据看起来像:

0x1F8B0800000000000400EDBD07601C499625262F6DCA7B7F4AF54AD7E.....(and a great many more bytes to come)......

【问题讨论】:

标签: sql sql-server vb.net picturebox


【解决方案1】:
  Private Sub sample()
    Dim command, commandReader As New NpgsqlCommand
    command.Connection = GetConnection()
    command.CommandText = "select imgField from imgtable"
    Dim productImageByte As Byte() = TryCast(command.ExecuteScalar, Byte())
    If productImageByte IsNot Nothing Then
        Using productImageStream As Stream = New System.IO.MemoryStream(productImageByte)
            PPicBoxPhoto.Image = Image.FromStream(productImageStream)
        End Using
    End If
End Sub

注意:这是我的代码示例,用于满足我的要求,使用 PostgreSQL 数据库和图像数据类型 bytea p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多