Groups | Blog | Home
all groups > sql server (alternate) > april 2004 >

sql server (alternate) : Problem with string


Qwiati
4/7/2004 10:13:07 PM
Hi
My user has put ' with editable place and then press enter so this same way
put text information with ' string into database.
When I try tu user command : UPDATE and try to change text with ' and use
command WHERE = ('text'') then I just received error command from SQL2000
server - I know what kind of problem is but i need your hel to get some
diferent command or method to change wrong put information
Thx for your qiuck help
Kayser

Steven Wilmot
4/7/2004 10:36:32 PM

[quoted text, click to view]

Replace any occurrence of {quote} in your string with {quote}{quote}.

e.g.

update mytable set field = ' doesn''t ... ' where field = 'does not'

S


Qwiati
4/8/2004 12:45:28 AM

[quoted text, click to view]
hmmm but let me show you what I have:
update mytable set field = 'blabla' where field = 'blabla" - this is my
problem because of the end of text I have in database have this --> ' <--
so if I set command: where filed = 'blabla" then I have .......syntax error
:D
Or I dont undersood waht you would like to tell me ;)

jay NO[at]SPAM allardworks.com
4/8/2004 7:25:09 AM
Maybe you should use a stored procedure or parameters instead of
building the string manually. Then you don't have to worry about the '
issue, and you don't have to worry about a sql injection attack.

instead of

sSQL = "update table set column='" + sSomeVariable + "' where x='" +
sSomeValue + "'"

do

sSQL = "update table set column=@sValue where x=@sKey"

Then, if it's a command object in ado or ado.net, add parameters to
your command object containing the values.

Personally, I prefer to put the update in the stored procedure then
pass parameters to the stored procedure.

But, if you want to do it the string way...

sSQL = "update table set column='" + replace(sSomeVariable, "'", "''")
+ "' where x='" + replace(sSomeValue, "'", "''") + "'"

Assuming vb/asp there. .net would be sSomeVariable.Replace("'", "''")




[quoted text, click to view]
Qwiati
4/10/2004 3:01:41 AM
Thx for your help guys it helps when I put double '''' at the and of command
:
update mytable set 'blabla' where field = 'blabla'''' - so the solution was
very easy
anyway thx for your help once more
Regards
Q

AddThis Social Bookmark Button