0

Hi i am using C# to connect to Access database.
The problem i am facing is not with database though.

I have used a statement like

string.Format("UPDATE TABLENAME SET FIELDNAME = \'{0}\' ", txtMembers.Text);

the problem i am facing is if the user enters 'hello', the whole text along with those apostrophes i get an error saying ''hello'' is giving a syntax error.

i have also tried changing \'{0}\' to \"{0}\".
Now in this case if i enter "hello" in the text box then it gives error due to the text generated ""hello"".

also if i enter hel"lo then the resulting query will be like FIELDNAME = "hel"lo which again gives an error.
Please help how can i deal with these escape characters

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by chiwawa10
0

Instead of escape characters, you can use the '@' symbol before the string.

E.g.
@"This is "an" example of 'escape' characters"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.