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.
Try 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) MsgBox(application_path) PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage End If Catch ex As Exception MsgBox(ex.ToString()) 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)) Try con.Open() cmd.ExecuteNonQuery() MessageBox.Show("Customer Added Sucsessfully !", "Save Customer") PictureBox1.Image = Nothing con.Close() Catch ex As Exception MessageBox.Show(ex.Message) 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 !