Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Do you have an idea how to solve the inverted commas (e.g. ") problem, when the user type it into the textbox and you send it to the database (you get a problem with your string). What's the best way that worked for you?
Posted

Mutant: I don't think SQL Server has a problem with single " but does have a problem with single '. He's probably using Access?

 

Anyway to the problem..

 

You could do a String.Replace("\"", "\"\"") or as mutant suggested, replace it with ' like so; String.Replace("\"", "'"). For SQL Server I usually just do a String.Replace("'", "''") (replace ' with two ''). There's also a SQL Server function which will take care of all of this for you, but unfortunately I can't remember what it is off of the top of my head.

Gamer extraordinaire. Programmer wannabe.
Posted

well, the the problem is indeed the '. the String.Replace is just great (Although you have to add it to any text you send and get back from the database.)

 

thanks

yaniv

Posted
You should only have to do a String.Replace() on data going into the database. Once it's in there it should be stored with single ' and retrieved with single ' as well.
Gamer extraordinaire. Programmer wannabe.
Posted
But. if i want the user to the dounle one - ", and not the single, i should do it twice - to replace it in the way to the database in some other, unused, char, and then to replace it again in the way to the app. the "problem" is that both are very usefull in hebrew so i have to make them usufull for the clinet.
Posted

Some thing happened to my post, what I meant was:

 

The string.replace is good if you want to change permanently one char to another, but if you want to keep the char (in the user point of view) then you have to replace it twice, one time when you send it to the database and one when you show it to the user again. Don't you?

Posted
I don't believe so. Like most other string alteration methods, it should return a string with the changes made and leave the current string in tact. I remember having a problem with this when trying to use String.Trim(), I had to do str = str.Trim(). Little odd IMO but it seems to be the way most methods work.
Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...