minglelinch
asked on
Handle " character in query statement string in C#
I have a problem to compose a query statement in C# with the record starting with " character.
I want to select a record which does not contain character double quote ".
e.g. select name from mytable where name is not null and name not like '"%'
In C#, When I
string sqlstring = " select name from mytable where name is not null and name not like '"%' ";
it looks like '"%' is not right. ???
Thanks.
I want to select a record which does not contain character double quote ".
e.g. select name from mytable where name is not null and name not like '"%'
In C#, When I
string sqlstring = " select name from mytable where name is not null and name not like '"%' ";
it looks like '"%' is not right. ???
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NP. Glad to help.
Alternative to the above, you can turn your string into a "raw" string, where backslash is just a backslash, by prefixing the string with an @ symbol. You would then escape your double-quotes with double-quotes themselves (a-la VB). Backslashes would not escape anything--even \n or \r.
Alternative to the above, you can turn your string into a "raw" string, where backslash is just a backslash, by prefixing the string with an @ symbol. You would then escape your double-quotes with double-quotes themselves (a-la VB). Backslashes would not escape anything--even \n or \r.
string sqlstring = @" select name from mytable where name is not null and name not like '""%' ";
ASKER