Problem with apostrophes

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
Back
Top