Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 1st, 2003, 06:16 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Question SQL Escape Characters for Access

Hi all,

I need to pass the contents of a text box to an Access database, problem is that the textbox could contain any normal character.

What is the escape character so that apostrophies won't cause the end of the string?

Cheers

Dave

Reply With Quote
  #2  
Old November 1st, 2003, 08:39 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,849 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 23 h 58 m 10 sec
Reputation Power: 766
For Microsoft databases, you need to convert single apostrophes to double ones ' '

You can use

sql = replace(sql, " ' ", " ' ' ")

I added some spaces for readability

Reply With Quote
  #3  
Old November 2nd, 2003, 01:07 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Yes!Doug G'anwser is correct!Plz replace the ' to the ''...

Reply With Quote
  #4  
Old November 2nd, 2003, 01:37 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
Cheers, but is there an standard rule? Would you always just type the character twice?

The textbox could hold and ASCII character. " ' ", " & ", " % " etc.

Reply With Quote
  #5  
Old November 2nd, 2003, 06:34 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Yes,It's SQL statement rule with using "..U can find some knowledge about it in the sql statement guide!...

Reply With Quote
  #6  
Old November 13th, 2003, 10:09 AM
jhertel jhertel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 jhertel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Rule for LIKE clauses

To escape special characters in LIKE clauses, the general rule is to enclose the character in [], e.g.[*] and [?].

Example:

select * from x where y like "[*]*"

will give you all records from table x where the y field starts with an asterisk (*).

Kind regards,
Jesper Hertel

Reply With Quote
  #7  
Old November 13th, 2003, 10:33 AM
jhertel jhertel is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 jhertel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
All LIKE escapes

I guess this must be the necessary escapes for LIKE operator arguments:

[ --> [[]
' --> ''
" --> ""
? --> [?]
* -->[*]
# --> [#]

I guess the ']' character does not need escaping, in contrast to the '[' character.

/Jesper

Last edited by jhertel : November 13th, 2003 at 10:37 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > SQL Escape Characters for Access


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway