Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

Problem with apostrophes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Schmitz - 14 May 2005 13:54 GMT
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
Mark Rae - 14 May 2005 20:24 GMT
> 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.
christian kuendig - 15 May 2005 09:29 GMT
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

>> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.