VB.NET将varbinary数据检索到图片框中

时间:2014-08-12 11:32:09

标签: sql sql-server vb.net picturebox

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

二进制数据类似于:

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

1 个答案:

答案 0 :(得分:0)

  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