Problem with apostrophes

G

Guest

Hi,

I currently use ADO.net to write to an access database using the
ExecuteNonQuery function and SQL INSERT statements. The data I write mostly
consists of names - which results in some problems: When I try to write names
like "O'Connor" or "O'Neal" the call fails ('cause of the ' ).
So, is there any way to write strings that contain apostrophes to a db using
SQL statements?

Thanks
Peter
 
M

Mark Rae

So, is there any way to write strings that contain apostrophes to a db
using
SQL statements?

Just replace all instances of a single apostrophe with a double apostrophe.
 
C

christian kuendig

a better aproach would be to use a parameter... (no chance for sql
injection)

SqlCommand cmd = new SqlCommand(connection, "UPDATE dbo.User set name =
@name WHERE id = @id");
cmd.Paramters.Add("@name", "O'Neil");
cmd.Parameter.Add("@id", (int)222);

let the wizard generate some code to persist a dataset (creating a data
adapter) and just go over this code

reards

Christian
 

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