Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

databinding image

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hi everyone,
I Created a dataset (and a datatable) Im binding three textboxes to the ds. All ok. Now I'm trying to bind a picture (to a picturebox) as well, but that doesn't work. Error message: "Cannot format the value to the desired type". Any suggestions....

Code:
        da.Fill(ds, "tblPatient")
        Dim dt As DataTable = ds.Tables("tblPatient")

            TextBox1.DataBindings.Add("Text", ds.Tables(0), "PatientNameLast")
            TextBox2.DataBindings.Add("Text", ds.Tables(0), "PatientNameFirst")
            TextBox3.DataBindings.Add("Text", ds.Tables(0), "PatientVerzGeldigTot")            
Dim b As New Binding("Image", ds.Tables(0), "PatientPicture")
            PictureBox1.DataBindings.Add(b)

Pampers [afro]
Keeping it simple can be complicated
 
Hi Guys,
I spent a good part of the day getting the databinding sorted. All well, except for that picture. And just when it is time to go to bed, just after you posted a thread to tek-tips, you give it a last Google and a last try, and believe it or not, it works.

The picture is stored in sql as a system.byte. To have it displayed as a picture, it has to be converted. Here is the code I used...

Code:
Private abyt() As Byte
....
Private Sub frmPatientStatus_Load
            abyt = CType(ds.Tables(0).Rows(0)(3), Byte())
            Dim ms As New IO.MemoryStream(abyt)
            Me.PictureBox1.Image = Image.FromStream(ms)
Sleep well

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top