Skip to content
Advertisement

Can’t find MySql.Data.MySqlClient.MySqlException insert query error

This is the error message

MySql.Data.MySqlClient.MySqlException: ‘You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ””)’ at line 1′

this is my query

I’ve been looking over at it for over an hour now and I still get this error.

Advertisement

Answer

It is recommended to use Parameterized Query.

UPDATED: As suggested by @CodeCaster for the concerns mentioned in Stop Using AddWithValue() article, I switch all the AddWithValue() to Add("@Parameter", SqlDbType).Value.

And also be sure that the value you pass with the SqlDbType must match the data type as respective database table column.

The reasons to use Parameterized Query are:

  1. It simplifies the query in passing the parameters and makes the query become more readable.
  2. Prevent SQL Injection.

Reference: Prepare MySQL Statement

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement