Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual 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 ASP Free Forums Sponsor:
  #1  
Old September 12th, 2003, 03:59 PM
boonkongw boonkongw is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 4 boonkongw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation VB Query Problem

I have a problem to create a query in vb which use access database. I want to search an employername John's Cafe from table EmployerInfo
The query as follow:
Stsql = "Select * from EmployerInfo where EmployerName = 'John's Cafe' "
It shows the syndax Error message!

Anybody knows how to solve this query. Thank you.

Reply With Quote
  #2  
Old September 12th, 2003, 05:06 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 32 m 56 sec
Reputation Power: 182
The query looks OK to me.

Reply With Quote
  #3  
Old September 13th, 2003, 04:45 PM
Psaxtiris Psaxtiris is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Athens - Greece
Posts: 41 Psaxtiris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
i think problem is here << 'John's Cafe' >>

try this

dim tex as string
tex= "John's Cafe"
Stsql = "Select * from EmployerInfo where EmployerName = ' "+ tex +" ' "

Reply With Quote
  #4  
Old September 13th, 2003, 05:42 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 32 m 56 sec
Reputation Power: 182
Psaxtiris has better eyesight The embedded ' in John's Cafe is probably the problem.

For MS databases, you need to escape the single ' with two of them.

Stsql = "Select * from EmployerInfo where EmployerName = 'John' 's Cafe' "

You can use the Replace function to turn all the single apostrophes into double one's (ignore extra spaces added for readability):

str = " 'John's Cafe' "
str = Replace (str, " ' ", " ' ' ")

Reply With Quote
  #5  
Old September 16th, 2003, 06:02 PM
K_SAJESH K_SAJESH is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 9 K_SAJESH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

HELLO,

The Queries having special caracters especially Single Quote i.e. '; Double Quote i.e. " and Pipe i.e. | will always give you problem

as the query that you have used contains single Quote it is obvious to give you problem.

Stsql = "Select * from EmployerInfo where EmployerName = 'John's Cafe' "

for that you can either reatrict these caracters by checking the keyascii in key press event or keycode in keydown event

E.g.
If KeyAscii = 34 Or KeyAscii = 39 Or KeyAscii = 124 Then
KeyAscii = 0
Exit Sub
End If

this code will prevent the user from entering the special caracters.

or you have to attach One more same special caracter along with it as shown below.

Select * from CustomerMaster where CustName = 'John''s Cafe'

Reply With Quote
  #6  
Old December 19th, 2003, 02:00 AM
tkapal tkapal is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 3 tkapal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi!

Here is the code i have and it works but some last data in the memo field is missing.

Private Sub Command16_Click()
On Error GoTo Err_Command16_Click

Dim oApp As Object
Dim SvcList As Control
Dim varItem As Variant
Dim SvcTitle As String
Dim SvcDetail As String



Set SvcList = Me!SvcTitleList

Set oApp = GetObject(, "Word.Application")


For Each varItem In SvcList.ItemsSelected

SvcTitle = Nz(SvcList.Column(1, varItem)) & vbCrLf

SvcDetail = Nz(SvcList.Column(1, varItem)) & vbCrLf & vbCrLf & _
Nz(SvcList.Column(2, varItem)) & vbCrLf & vbCrLf


With oApp
.ActiveDocument.Bookmarks("Services").Range.Text = SvcTitle
.ActiveDocument.Bookmarks("SvcDetailBM").Range.Text = SvcDetail

End With


Next varItem
Exit_Command16_Click:
Exit Sub

Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click

End Sub

Thanks again,
tkapal

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VB Query Problem


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





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek