Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server CE / April 2007

Tip: Looking for answers? Try searching our database.

Text Delimiters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nigel Vandyk - 16 Apr 2007 21:58 GMT
I am sure that lots of people must know the answer to this but I can't find
it anywhere.

If I want to insert a Firstname and Surname into an SQLCE table called
Clients I would use

INSERT INTO Clients (Firstname,Surname) VALUES('Fred','Bloggs')

but what happens if I want to insert Paddy O'Brian or Michael O'Connor

Because we are using an apostrophe in their names, this will cause the
Insert statement to fail

In Access I would use chr(34) to delimit the strings. Is there a way round
this in SQLSERVERCE?

Signature

With best wishes

Nigel Vandyk

Website:www.astarsoftware.co.uk

William (Bill) Vaughn - 16 Apr 2007 22:24 GMT
This problem can be solved by either doubling the single quotes as in
   ... 'O''Malley',...
or (better yet) use Parameters for your input parameters. These solve other
framing issues (as when using dates etc.)

hth

Signature

____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest books:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and
Hitchhiker's Guide to SQL Server 2005 Compact Edition

-----------------------------------------------------------------------------------------------------------------------

>I am sure that lots of people must know the answer to this but I can't find
>it anywhere.
[quoted text clipped - 11 lines]
> In Access I would use chr(34) to delimit the strings. Is there a way round
> this in SQLSERVERCE?
Nigel Vandyk - 16 Apr 2007 22:40 GMT
Thanks very much for that, Bill

Signature

With best wishes

Nigel Vandyk

Website:www.astarsoftware.co.uk

> This problem can be solved by either doubling the single quotes as in
>    ... 'O''Malley',...
[quoted text clipped - 18 lines]
>> In Access I would use chr(34) to delimit the strings. Is there a way
>> round this in SQLSERVERCE?
Adam - 16 Apr 2007 22:57 GMT
Dnia Mon, 16 Apr 2007 21:58:07 +0100, Nigel Vandyk napisał(a):

> I am sure that lots of people must know the answer to this but I can't find
> it anywhere.
> In Access I would use chr(34) to delimit the strings. Is there a way round
> this in SQLSERVERCE?

Use Parameters

SQL = "INSERT INTO USERS (name, surname) VALUES (?, ?)";
zapytanieSQL = new SqlCeCommand(SQL, polaczenie);
zapytanieSQL.Parameters.Add(new SqlCeParameter("name",
SqlDbType.nvarchar));
zapytanieSQL.Parameters.Add(new SqlCeParameter("surname",
SqlDbType.nvarchar));
zapytanieSQL.Prepare();              
zapytanieSQL.Parameters["name"].Value = your string
zapytanieSQL.Parameters["surname"].Value = your string
zapytanieSQL.ExecuteNonQuery();
zapytanieSQL.Parameters.Clear();
 
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



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