Question by brainsmith78: Replace apostrophe (‘) in MySql with ASP.NET?
Ok, so I have been searching for a couple of hours for an answer to this. I have found loads when it comes to MySql and PHP, but not ASP.NET.
I am working on an Intranet for a client and the system updates the MySql database with data entered by the user. This data can include names, addresses, and notes, so it is very likely apostrophes will need to be entered. I found this post: http://answers.yahoo.com/question/index?qid=20080325085636AAp3sjp and I tried using the backslash, but it didn’t work.
I am using this to replace the apostrophe:
strOrderNotes.Replace(” ‘ “, ” \’ “) (There are no blank spaces in the actual code, I just spaced it out here so you could see.)
strOrderNotes is a variable of type string. I used the replace(” ‘ “, ” ‘ ‘ “) method before on a SQL Server database and it worked, but not with MySql.
I do not have enough room to post my code, but I will post a snippet if requested.
Answer by Daniel B
One option to solve the basic problem here is to use parametrized queries instead of just concatenating strings to make an SQL statement. The parametrized queries it doesn’t make a difference what characters are in your fields, and it also helps protect you against SQL injection exploits. You can find more info here:
Add your own answer in the comments!
There are no revisions for this post.