How to store the string with single quote in Microsoft SQL Server CE 2.0 using C# CF programme

M

micmic

Deear all experts,

In the MySQL, we can use escape character '\' to save the STRING WITH
single quote into database (eg. we would like to insert into table
"tbl_ABC"with the string ab'c, we can use the following SQL query to insert
into database : Insert into tbl_ABC VALUES ('ab\'c'); ). Also there is some
functions in mySQL api so that we can save the single quote into MySql
database using C programme. But it seems that i cannot do so in the PDA
using Microsoft SQL Server CE 2.0. How to save the single quote string using
SQL for Microsoft SQL Server CE 2.0 . Is there any functions in C# to save
the single quote string into database ?

Best wishes,
Michael
 
J

Jon Skeet [C# MVP]

micmic said:
In the MySQL, we can use escape character '\' to save the STRING WITH
single quote into database (eg. we would like to insert into table
"tbl_ABC"with the string ab'c, we can use the following SQL query to insert
into database : Insert into tbl_ABC VALUES ('ab\'c'); ). Also there is some
functions in mySQL api so that we can save the single quote into MySql
database using C programme. But it seems that i cannot do so in the PDA
using Microsoft SQL Server CE 2.0. How to save the single quote string using
SQL for Microsoft SQL Server CE 2.0 . Is there any functions in C# to save
the single quote string into database ?

As with everything else: don't put the parameter values directly into
your SQL command. Use parameterised queries/updates/inserts/deletes,
and set the value of the parameter. The driver will then take care of
making sure the data is quoted if necessary.
 
P

Picho

Dont know about SQL Server CE 2.0 - but did you try the old fashion SQL way?

INSERT INTO tbl_ABC VALUES ('ab''c') - this is double single-quote there
case you missed it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top