Replace apostrophe (‘) in MySql with ASP.NET?

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.

Best answer:

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:

http://www.dailycoding.com/Posts/addparameterizedqueriesinmysqloledb.aspx

Add your own answer in the comments!

No related content found.

Revisions

There are no revisions for this post.

Tags: , , ,

No comments yet.

Leave a Reply