0

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.

3 Answers3

3

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.

Community
  • 1
  • 1
Novice
  • 2,447
  • 3
  • 27
  • 33
3

Jose is right - you should absolutely use parameterized queries.

This avoids:

  • SQL injection attacks
  • Invalid SQL due to quotes etc
  • Issues with date/time and numeric formats

It's also just a generally good idea to separate code from data.

See Bobby Tables for more.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

Use the SQL escape character ''.

'O''Neil'

ref : http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries

Drahakar
  • 5,986
  • 6
  • 43
  • 58