Reputation: 11
One of my names in my data looks like this O'Neil
When I am putting this into my MySQL Query it looks like this 'O'Neil' Unfortunately it reads the ' between the O and causes an error. I Don't want to replace the ', I still want the name to be O'Neil. Can anyone recommend a way to do this?
I'm using C# (.Net).
Thanks.
CM888.
Upvotes: 0
Views: 1004
Reputation: 2487
You should use parameterized queries.Answers for this post are examples of parameterized queries.Indirectly you are performing sql Injection. parameterized queries avoids sql injection and moreover it is a good practice too.
Upvotes: 3
Reputation: 1503859
Jose is right - you should absolutely use parameterized queries.
This avoids:
It's also just a generally good idea to separate code from data.
See Bobby Tables for more.
Upvotes: 3
Reputation: 6088
Use the SQL escape character ''.
'O''Neil'
ref : http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries
Upvotes: 2