I'm trying to save a picture into a database and here is my source code
'putting a picture into a picturebox
If StudentPictureBox.Image Is Nothing Then
Exit Sub
End If
Dim ms As MemoryStream = New MemoryStream
StudentPictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
'converting it
Dim bytBlobData(ms.Length - 1) As Byte
ms.Position = 0
ms.Read(bytBlobData, 0, ms.Length)
Dim DatabaseParameter As New MySql.Data.MySqlClient.MySqlParameter("@BlobData", MySql.Data.MySqlClient.MySqlDbType.Blob, bytBlobData.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, bytBlobData)
'connecting to the database
Dim ConnectionString As String = "server=localhost; user id =root;password=root;database=picturedb;"
Dim QueryString As String = "INSERT INTO blobtest(BlobData) VALUES(@BlobData)"
myConnection = New MySql.Data.MySqlClient.MySqlConnection
myConnection.ConnectionString = ConnectionString
myCommand = New MySql.Data.MySqlClient.MySqlCommand
myCommand.CommandText = QueryString
myCommand.Connection = myConnection
myCommand.Parameters.Add(DatabaseParameter)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Catch CommandError As MySql.Data.MySqlClient.MySqlException
MessageBox.Show(CommandError.Message)
End Try
it keeps giving me an error saying that there is something wrong with the command control

New Topic/Question
This topic is locked




MultiQuote


|