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

You don't have to escape ' marks in C#, remove the \ characters.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.