This is my code to insert the image into an Access DB. The problem is when I insert player image at the first time it works. but when I add another player to the DB and choose another image, it takes the first one. How I can clear the MemoryStream using VB.NET 2015.
Dim conn As New OleDbConnection("provider=microsoft.ace.oledb.12.0; Data Source=SoccerTimeDB.accdb")
Dim cmd As New OleDbCommand("", conn)
Dim ms As New MemoryStream
Sub Runcommand(Sqlcommand As String, Optional message As String = "")
Try
If conn.State = ConnectionState.Closed Then conn.Open()
cmd.CommandText = Sqlcommand
cmd.ExecuteNonQuery()
If message <> "" Then MsgBox(message)
Catch ex As Exception
MsgBox(ex.Message)
Finally
If conn.State = ConnectionState.Open Then conn.Close()
End Try
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
playerImage.Image.Save(ms, playerImage.Image.RawFormat)
Dim img() As Byte
img = ms.ToArray()
Dim strCmd As String = "insert into playerData values (" & playerNumberTB.Text & "," & playerIdTB.Text & ",'" & playerNameTB.Text & "', @Img) "
cmd.Parameters.AddWithValue("@Img", img)
Runcommand(strCmd, "player has been added")
End Sub