hy This function converts byte array to image:
Public Shared Function ByteArrayToImage(ByVal ByteArr() As Byte) As Object
Dim ImageStream As System.IO.MemoryStream
Try
If ByteArr.GetUpperBound(0) > 0 Then
ImageStream = New System.IO.MemoryStream(ByteArr)
Return Image.FromStream(ImageStream)
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function
and this convert back:
Public Shared Function ImageToByteArray(ByVal NewImage As Image) As Object
Dim ImageStream As System.IO.MemoryStream
Dim ByteArr() As Byte
Try
ReDim ByteArr(0)
If NewImage IsNot Nothing Then
ImageStream = New System.IO.MemoryStream
NewImage.Save(ImageStream, Imaging.ImageFormat.Jpeg)
ReDim ByteArr(CInt(ImageStream.Length - 1))
ImageStream.Position = 0
ImageStream.Read(ByteArr, 0, CInt(ImageStream.Length))
End If
Return ByteArr
Catch ex As Exception
Return Nothing
End Try
End Function
+You need DBNull check when the column allow nulls.