Hello i'm having a little problem here.
First when my form is loaded it gets information from database (ms accsses)
But if i make some changes in textboxes and click save button it doesn't read the picturebox that it has image on it.
Because when form loads it loads the image in the Picturebox, then i just wanted to edit some text and click save and it will not allow me , because the picturebox is empty for him.
Lets start with the read information:
Try
With cmd
Dim stream As New IO.MemoryStream()
conn.Open()
.Connection = conn
.CommandText = "select cPicture from Table where ID=@uID"
.Parameters.Add("@uID", OleDbType.Integer, 50).Value = TextBox6.Text
Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
stream.Write(image, 0, image.Length)
Dim bitmap As New Bitmap(stream)
PictureBox1.Image = bitmap
stream.Close()
.Parameters.Clear()
End With
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
If conn IsNot Nothing Then
conn.Close()
End If
End Try
Here will display me the picture inside the picturebox (result is okay)
Now for save :
Try
With cmd
Dim ms As New IO.MemoryStream()
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
Dim arrimage() As Byte = ms.GetBuffer
If Not PictureBox1.Image Is Nothing Then
MsgBox("missing")
Else
MsgBox("has")
End If
conn.Open()
.Connection = conn
.CommandText = "UPDATE Table SET cName = @uName,cNumber = @uNumber,cSupplier = @uSupp,cStore = @uStore,cCount = @uCount,cPicture = @picture WHERE ID = 1"
.Parameters.Add("@uName", OleDbType.VarChar, 50).Value = TextBox1.Text
.Parameters.Add("@uNumber", OleDbType.BigInt, 50).Value = TextBox2.Text
.Parameters.Add("@uSupp", OleDbType.VarChar, 50).Value = TextBox3.Text
.Parameters.Add("@uStore", OleDbType.VarChar, 50).Value = TextBox4.Text
.Parameters.Add("@uCount", OleDbType.Integer, 50).Value = TextBox5.Text
.Parameters.Add("@Picture", OleDbType.Binary).Value = arrimage
.ExecuteNonQuery()
.Parameters.Clear()
ms.Close()
End With
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
If conn IsNot Nothing Then
conn.Close()
End If
End Try
And here gives me the message:
MsgBox("missing")
And query required 6 stuff to make the change.
How to solve it?
What I have tried:
don't know exactly where the problem comes