c# - How to Escape special characters in Microsoft SQL CE -
nb: using microsoft sql compact edition 3.5
i have table of users.i have display name user input , need query user display name matches input.
select top (1) * users display_name 'abby parker'
here 'abby parker'
input
it working fine in normal cases .but problem display name can contain special characters
for eg display name can "abby park#er"
or "%&^%&^%#%"
.the above query fails in such cases .i have tried solution specified here
escaping special characters in sql statement using sql parameters
this how building query here
var command = ceconnection.createcommand(); command.commandtext = string.format("select top (1) * {0} {1} '[{2}]' ", tablename,fieldname, key); }
- {0}=>users
- {1}=>display_name
- {2}=>pattern
thanks in advance
as posted here, please try following:
var command = ceconnection.createcommand(); command.commandtext = string.format("select top (1) * {0} {1} @key ", tablename, fieldname); command.parameters.addwithvalue("@key", key);
Comments
Post a Comment