I'm modifying a code which can save an image into the database. I've changed everything that i need to change but when i click the save button the error says that i have an error in the INSERT INTO statement. Here is the code:
Dim conn As New OleDbConnection(cn)
'save Image to database
Try
If Me.TextBox1.Text.Trim = "" Then
MsgBox("Please browse a picture to save!", MsgBoxStyle.Information, "No Picture to Save")
Exit Sub
End If
Dim ms As New MemoryStream
Me.imgsave.Image.Save(ms, Me.imgsave.Image.RawFormat)
Dim arrayImage() As Byte = ms.GetBuffer
ms.Close() ' Closes the Memory Stream
Dim nStr As String = Me.TextBox1.Text.Substring(Me.TextBox1.Text.LastIndexOf("\") + 1)
Dim strQuery As String = "INSERT INTO pic (Image) VALUES(@Image)"
Dim objcommand As New OleDbCommand(strQuery, conn)
With objcommand
.Parameters.Add(New OleDbParameter("@Image", SqlDbType.Image)).Value = arrayImage
End With
conn.Open()
objcommand.ExecuteNonQuery()
MessageBox.Show("Image Saved Into the DataBase", "Save Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information)
conn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
End Try
The name of my database table is pic and Image is the name of the column. Please. thank you for your replies everyone. :) I just don't know what's wrong with my statement.