Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello fellow coders
am new at vb
i have been able to save a picture and other data, in a access database and am able to display it in the picturebox ,but am unable to Edit the picture,i can edit all the other data but when it comes to pictures it gives me this error,
"Type of value has a mismatch with column typeCouldn't store <system.drawing.bitmap> in PICTURE Column. Expected type is Byte[]"
here's my code for editing

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
If inc <> -1 Then
ds.Tables("hip").Rows(inc).Item(1) = txtidNumber.Text
ds.Tables("hip").Rows(inc).Item(2) = txtFirstName.Text
ds.Tables("hip").Rows(inc).Item(3) = txtMiddleName.Text
ds.Tables("hip").Rows(inc).Item(4) = txtSurName.Text
ds.Tables("hip").Rows(inc).Item(5) = cboGender.Text
ds.Tables("hip").Rows(inc).Item(6) = txtLocation.Text
ds.Tables("hip").Rows(inc).Item(7) = txtPhone.Text
ds.Tables("hip").Rows(inc).Item(8) = txtEmail.Text
ds.Tables("hip").Rows(inc).Item(9) = txtNotes.Text
Dim bytes As [Byte]() = ds.Tables("hip").Rows(inc).Item(10)
Dim ms As New MemoryStream(bytes)
picPhoto.Image = Image.FromStream(ms)
ds.Tables("hip").Rows(inc).Item(10) = picPhoto.Image------(ERROR HERE)---"Type of value has a mismatch with column typeCouldn't store <system.drawing.bitmap> in PICTURE Column. Expected type is Byte[]"
da.Update(ds, "hip")
MsgBox("DATA EDITED")
End If
End Sub
Posted

1 solution

The error message is pretty explicit: "Type of value has a mismatch with column type Couldn't store in PICTURE Column. Expected type is Byte[]"
You are passing an Image to a column that expects an array of bytes. So try converting the Image to a byte array:
VB
Dim ms As New MemoryStream()
picPhoto.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
ds.Tables("hip").Rows(inc).Item(10) = ms.ToArray()
 
Share this answer
 
Comments
Member 10436009 30-Nov-13 10:15am    
it worked but here is the problem i have to log out so that the program can accept changes that i have given it is there a way or code i can add so that there immediate changes are inserted into it,your help would be highly appreciiated
OriginalGriff 30-Nov-13 10:18am    
Sorry? That doesn't make any sense to me - remember I can't see your screen, access your HDD or read your mind: so I only get what information you give me, not any background context.
Member 10436009 30-Nov-13 10:38am    
ok lemme explain what am saying,after i have saved,edited or deleted the data from the database,it keeps on appearing on the windows form until i exit or close the windows form,when i load it again is when the data deleted disappears,the data saved shows or the data edited shows. in short the changes i make or made doesn't appear untill i have exited and loaded the form again.
OriginalGriff 30-Nov-13 10:43am    
The code you show doesn't deal with any display controls - so you need to explain exactly how the code above is related to to the display. There are a huge number of different ways you could be doing this, and I don't like to guess! ;)
Member 10436009 30-Nov-13 10:59am    
ok

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