I know this ia a basic question and i’m embarassed to ask it but i have this query that contains a string with a single quote in it that goes like this:
Update Table123 Set Field=@Field Where blablabla
I then pass a dictionary as a parameter with Field
as key and 123'123
as value.
‘Field’ data type : nvarchar(500)
This is how i add the parameters to the query. SqlCmd is the query and ParamsList is the dictionary
I can see the right value in debug up until the command runs but once it does, i don’t get an error but the value saved is only 123
I mean i use this concept everyday and never had an issue. Am i missing something here?
6
Perhaps you need to escape the single literal quote by doubling it up:
value = "123''123"
Using two contiguous single quotes is the ANSI standard way of escaping a literal single quote in SQL.
2
As the above answer mentioned, using double quotes should work.
This also worked in postgres.
INSERT INTO test (field) VALUES (E'123'123');
select * from test;
-- 123'123
2