PC Review


Reply
Thread Tools Rate Thread

RE Quotation marks

 
 
LP
Guest
Posts: n/a
 
      11th Jun 2007
Hi,

I need to use ' or " in my query. Access allows me to key in eg "Mother's
boy" but when using the find command to search for the field with ' or "
VB gives errors. eg: rs.find "name = '" & field & "'"
and if the field contains ' or " VB stopped working.

I remember you need to use double "" if you there is a " in your record.
I've forgotton about the rules. Can someone help?

thanks


 
Reply With Quote
 
 
 
 
AMDRIT
Guest
Posts: n/a
 
      11th Jun 2007
The simplest way around your delima is to use paramaterized queries. This
technique is already build into ADODB and ready for your use. In this way,
you will not have to remember the rules for quotes, dates, numbers or the
like.

Another way to manage strings is with the assistance of a helper function.
You simply carry it with you in all your code projects, then you won't have
to remember the rules.

public function FixSQLString(input as string) as string

'Remember to test for stand alone semicolons as they can present potential
SQL Injection Attacks.

dim sTemp as string = input

'Close single quotes
stemp = stemp.replace("'", "''")

'Close double quotes
stemp = stemp.replace("""", """""")

return stemp

end function

Now when you are building a SQL query or a datatable filter, you can simply
pass the test value to the function first

rs.find("name = '" & FixSQLString(field) & "'")

or even better

rs.find (string.format("name='{0}'", FixSQLString(field))

I challenge your use of the ADO 2x-3x library instead of ADODB.net 1x-2x
libraries. Both support paramterized queries but only ADODB will give you
rich native support in .Net and follow along the general thinking of
development in MS technology space.

"LP" <(E-Mail Removed)> wrote in message
news:f4iabl$fmj$(E-Mail Removed)...
> Hi,
>
> I need to use ' or " in my query. Access allows me to key in eg "Mother's
> boy" but when using the find command to search for the field with ' or "
> VB gives errors. eg: rs.find "name = '" & field & "'"
> and if the field contains ' or " VB stopped working.
>
> I remember you need to use double "" if you there is a " in your record.
> I've forgotton about the rules. Can someone help?
>
> thanks
>



 
Reply With Quote
 
LP
Guest
Posts: n/a
 
      12th Jun 2007
Thanks Amdrit. It works.

"AMDRIT" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The simplest way around your delima is to use paramaterized queries. This
> technique is already build into ADODB and ready for your use. In this
> way, you will not have to remember the rules for quotes, dates, numbers or
> the like.
>
> Another way to manage strings is with the assistance of a helper function.
> You simply carry it with you in all your code projects, then you won't
> have to remember the rules.
>
> public function FixSQLString(input as string) as string
>
> 'Remember to test for stand alone semicolons as they can present potential
> SQL Injection Attacks.
>
> dim sTemp as string = input
>
> 'Close single quotes
> stemp = stemp.replace("'", "''")
>
> 'Close double quotes
> stemp = stemp.replace("""", """""")
>
> return stemp
>
> end function
>
> Now when you are building a SQL query or a datatable filter, you can
> simply pass the test value to the function first
>
> rs.find("name = '" & FixSQLString(field) & "'")
>
> or even better
>
> rs.find (string.format("name='{0}'", FixSQLString(field))
>
> I challenge your use of the ADO 2x-3x library instead of ADODB.net 1x-2x
> libraries. Both support paramterized queries but only ADODB will give you
> rich native support in .Net and follow along the general thinking of
> development in MS technology space.
>
> "LP" <(E-Mail Removed)> wrote in message
> news:f4iabl$fmj$(E-Mail Removed)...
>> Hi,
>>
>> I need to use ' or " in my query. Access allows me to key in eg
>> "Mother's boy" but when using the find command to search for the field
>> with ' or " VB gives errors. eg: rs.find "name = '" & field & "'"
>> and if the field contains ' or " VB stopped working.
>>
>> I remember you need to use double "" if you there is a " in your record.
>> I've forgotton about the rules. Can someone help?
>>
>> thanks
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My question marks, apostrophies and quotation marks are weird. pj Microsoft Word Document Management 1 10th Jan 2008 10:26 AM
Why do quotation marks change to question marks in e-mails receiv. =?Utf-8?B?SiBIZXJuZG9u?= Microsoft Outlook Discussion 0 30th May 2007 09:01 PM
without quotation marks? =?Utf-8?B?amZheno=?= Microsoft Excel Misc 1 2nd Mar 2006 05:43 PM
Re: Quotation Marks Piotr Kosinski Microsoft Excel Programming 0 31st Aug 2005 10:57 AM
Punctuation marks and quotation marks 29erKilo Microsoft Word New Users 8 19th Aug 2004 03:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:02 AM.