Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim db As New DataContext("Data Source=.\SQLEXPRESS;Initial Catalog=DBMSTW;Integrated Security=True")
        Dim emp As Table(Of Employee) = db.GetTable(Of Employee)()
        Dim query = From p In emp _
                  Where p.emp_id = "E58" Select p
        For Each p In query
            EmpID.Text = p.emp_id
            EmpName.Text = p.emp_name
            If (p.gender = "F") Then
                Female.Checked = True
            Else
                Male.Checked = True
            End If
            EmpAge.Text = p.age
            Dim Img As Image
            Dim ImgByte As Byte() = Nothing

            Dim stream As MemoryStream
            ImgByte = CType(p.img_data, Byte())            
stream = New MemoryStream(ImgByte, 0, ImgByte.Length)
            Img = Image.FromStream(stream)
            EmpImg.Image = Img

        Next

In Above Code There is Error in Underlined Part. I want to retrive image into picturebox EmpImg. But I dont know how to convert it into using LINQ to SQL.

Error Message is

Value of type 'System.Data.Linq.Binary' cannot be converted to '1-dimensional array of Byte'.
Posted

1 solution

I have a similar use case in an application and this is set to write the contents of the binary image data to a user control:
VB
imgBytes = imgRow.ImageData.ToArray
Using mStream As New System.IO.MemoryStream(imgBytes)
    Using qImg As System.Drawing.Image = System.Drawing.Image.FromStream(mStream)
        Response.ContentType = mimeDict(qImg.RawFormat.Guid).MimeType
        Response.BinaryWrite(imgBytes)
    End Using
End Using


For your situation, though...you may be able to get away with just changing
VB
ImgByte = CType(p.img_data, Byte())

TO
VB
ImgByte = CType(p.img_data.ToArray, Byte())
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900