VB.NET将变位数据检索到图片框中。

问题描述 投票:0回答:1

我在SQL Server中的一些数据,在一个叫 "S "的网站上。VARBINARY 列,我只是想知道如何将它显示为一个 PictureBox 在VB.NET中。怎么做呢?

二进制数据看起来是这样的。

0x1F8B0800000000000400EDBD07601C499625262F6DCA7B7F4AF54AD7E.....(and a great many more bytes to come)......
sql sql-server vb.net picturebox
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.