I am barely new to VB.NET and as part of our final project, we are tasked to create a program and use MS Access as our database. Now the problem is whenever we are 'Updating' the picture in our database, the error will always show System.Data.OleDb.OleDbException (0x80004005): Could not save; currently locked by another user. And the funny thing is that when we repeatedly click the Update Button it will now prompt Account updated and proceeds to update the picture in the database. How can I fix this?
Our code is as follow:
Using modify As New OleDbCommand("Update AccountDetails Set [Picture] = @Picture WHERE ID = " & id_modify & "", connect)
connect.Close()
connect.Open()
Dim arrImage() As Byte
Dim mstream As New System.IO.MemoryStream()
picNewAccnt.Image.Save(mstream, Imaging.ImageFormat.Png) 'the picture box that will show the picture inserted
arrImage = mstream.GetBuffer
Dim filesize As UInt32
filesize = mstream.Length
mstream.Close()
mstream.Dispose()
Try
modify.Parameters.AddWithValue("@Picture", arrImage)
modify.ExecuteNonQuery() 'the part where the error always occur
MsgBox("Account updated ", MsgBoxStyle.Information, "Account Update Successful")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using
I tried checking all connections to the database and making sure that it is enclosed in the Using Statement.