1

I'm using MySqlCommand for perform query insert in my vb.net application, now I've this query:

UPDATE primo_appointments SET 
  book_datetime = @parameter1, 
  start_datetime = @parameter2, 
  end_datetime = @parameter3, 
  notes = @parameter4, 
  hash = @parameter5, 
  is_unavailable = @parameter6 
WHERE hash = xqA5jdsFBLPTrvy5kKHfgXBZdv9Hs2Ld 
  AND lastUpdated = 12-01-2016 15:53:47.3978486

when I do: .ExecuteNonQuery() this error appear:

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 '15:53:47.3978486' at line 1.

What is wrong?

0

2 Answers 2

1

Your lastUpdated and hash is not enclosed in single quotes which is the cause of your error.

The fix for this is not to enclose it in quotes, but to use a parameter for these values as well as the others:

UPDATE primo_appointments SET 
  book_datetime = @parameter1, 
  start_datetime = @parameter2, 
  end_datetime = @parameter3, 
  notes = @parameter4, 
  hash = @parameter5, 
  is_unavailable = @parameter6 
WHERE hash = @oldHashString
  AND lastUpdated = @lastUpdatedDate

When you use a parameterised list, you don't have to remember whether a field needs to be surrounded by quotes or not - this is handled for you. It also protects you from SQL injection attacks.

Sign up to request clarification or add additional context in comments.

2 Comments

It is strange how many apparently think a parameter wont work on the WHERE clause
The same parameter if inserted as @param work, but if I execute the query without put Where parameter into the parametizer value won't work.
0

your varchar should between 2 ', you query should be:

UPDATE primo_appointments SET book_datetime = @parameter1, 
start_datetime = @parameter2, end_datetime = @parameter3, 
notes = @parameter4, hash = @parameter5, is_unavailable = @parameter6 
WHERE hash = 'xqA5jdsFBLPTrvy5kKHfgXBZdv9Hs2Ld' 
AND lastUpdated = '12-01-2016 15:53:47.3978486'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.