I am trying to download and display an image that I had previously uploaded to SQL Server database and keep getting this error below.
Value of type '1-dimensional array of System.Object' cannot be converted to '1-dimensional array of Byte' because 'System.Object' is not derived from 'Byte'
Here is the code I am working with, I would appreciate any input. I am sure it is something simple that I am missing.
Private Sub btnDownloadImg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadImg.Click
Try
Dim strConn As String = "Data Source=RSTACY260;User ID=sa;Initial Catalog=UpLoadImage;Password=atruhoo"
Dim conn As New SqlConnection(strConn)
conn.Open()
Dim cmdDownload As New SqlCommand("select * from TestImageTable")
cmdDownload.Connection = conn
cmdDownload.CommandType = CommandType.Text
Dim da As New SqlDataAdapter(cmdDownload)
Dim ds As New DataSet
da.Fill(ds)
Dim bits As Byte
bits = CType(ds.Tables(0).Rows(0).ItemArray, Byte())
Dim memorybits As New MemoryStream(bits)
Dim bitmap As New Bitmap(memorybits)
PictureBox1.Image = bitmap
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Value of type '1-dimensional array of System.Object' cannot be converted to '1-dimensional array of Byte' because 'System.Object' is not derived from 'Byte'
Here is the code I am working with, I would appreciate any input. I am sure it is something simple that I am missing.
Private Sub btnDownloadImg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadImg.Click
Try
Dim strConn As String = "Data Source=RSTACY260;User ID=sa;Initial Catalog=UpLoadImage;Password=atruhoo"
Dim conn As New SqlConnection(strConn)
conn.Open()
Dim cmdDownload As New SqlCommand("select * from TestImageTable")
cmdDownload.Connection = conn
cmdDownload.CommandType = CommandType.Text
Dim da As New SqlDataAdapter(cmdDownload)
Dim ds As New DataSet
da.Fill(ds)
Dim bits As Byte
bits = CType(ds.Tables(0).Rows(0).ItemArray, Byte())
Dim memorybits As New MemoryStream(bits)
Dim bitmap As New Bitmap(memorybits)
PictureBox1.Image = bitmap
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub