Hi guys. Today I want help from you experts. This will help others as well. Okay. Directly to the topic.
My senario is this. I want to save image to mysql database. By this way. There was table contain two data columns. which are ID and Image path.
So now you know my method. I want to save image path to database.
For the first I want to get image path location. I used open file dialog box to this. code is below.

            With OpenFileDialog1
                .Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;")
                .FilterIndex = 4
            End With
            'Clear the file name
            OpenFileDialog1.FileName = ""
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                application_path = (OpenFileDialog1.FileName.ToString)
                PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            End If
        Catch ex As Exception
        End Try

there is variable name application_path. To that varibale get path as string.
NOTE- I made variable below the "Public class Form1" code.

Dim application_path as string

Then I had one text box to input "ID" and there is picture box preview image and button named "save"
save button code is below :

query = "INSERT INTO test.test(id, path" & _
                    "VALUES (@id, @path)"
            Dim cmd As MySqlCommand = New MySqlCommand(query, con)
            cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox1.Text))
            cmd.Parameters.AddWithValue("@path", (application_path))
                MessageBox.Show("Customer Added Sucsessfully !", "Save Customer")

                PictureBox1.Image = Nothing

            Catch ex As Exception
            End Try

But when I run this code. There is error occur and say:
" you have an error in your sql syntax. check the mannual corresponed to your mysql server version for the right syntax to use near"

But code look like fine. I couldn't understand where the error. So please help me guys.
Thank You !

Member Avatar

Should your query be more like:

query = "INSERT INTO test.test(id, path) " & _
                    "VALUES (@id, @path)"

? A closing parenthesis and a space following it. The error message wasn't anything with the code, per se, but specific to the query itself. Hope this helps.

You can directly mention the parameters without mentionning the field names.

query = "INSERT INTO test.test VALUES (@id, @path)"

But, at the time of adding the parameters with command object you must have to maintain the serial by which the parameter names were written in SQL syntax.

oh That's unfogivable mistake I did. Thank you all :)