473,473 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RE Quotation marks

LP
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
Jun 11 '07 #1
2 1166
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" <lp@yahoo.comwrote in message
news:f4**********@mawar.singnet.com.sg...
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

Jun 11 '07 #2
LP
Thanks Amdrit. It works.

"AMDRIT" <am****@hotmail.comwrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
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" <lp@yahoo.comwrote in message
news:f4**********@mawar.singnet.com.sg...
>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


Jun 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: NikkoW | last post by:
I need to assign a string to a variable but the text string includes quotation marks: Example: MyString = "He turned and said "Hello" before leaving." When the compiler hits the quotation...
8
by: Stephen Poley | last post by:
One disadvantage of using a simple text editor to produce HTML is that it is relatively time-consuming to put in the proper typographical quotation marks and dashes. A round tuit having arrived...
63
by: Tristan Miller | last post by:
Greetings. Do any popular browsers correctly support <q>, at least for Western languages? I've noticed that Mozilla uses the standard English double-quote character, ", regardless of the lang...
4
by: Thomas Miskiewicz | last post by:
Hi! Is using of a double quotation mark with a URL a problem? For example: http://myserver.com/query?field1=something&field2=test&params="field1=test1"+"field2=test2" Regards Thomas
7
by: Paradigm | last post by:
I am trying to create a recordset where some text fields are matching. The problem is that some of the text fields contain quotation marks. I have tried to create the sql string using replace eg....
0
by: Aaron Deskins | last post by:
Hello all, I'm trying to set up a database to track articles and documents. I've created a Table to hold the information I need. I've set up one of the fields to hold the actual text of the...
2
by: Dixie | last post by:
Hi, I am tyring to write some generic code that will send the source SQL for a mailmerge to a Word template. I am trying to use DLookup to insert the query name that is the record source for the...
3
by: Ufit | last post by:
Simple,dumm question - how to include quotation marks in the string? F.ex. "Data Source=.\SQLEXPRESS;AttachDbFilename="C:\client data.mdf";Integrated Security=True;User Instance=True" I get syntax...
31
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and...
3
by: Junior | last post by:
I want to open a text file for reading and delineate it by comma. I also want any data surrounded by quotation marks that has a comma in it, not to count the commas inside the quotation marks ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.