Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need the code to replace " with its ascii to avoid errors in a sql statement.

Posted on 2003-03-18
7
Medium Priority
?
178 Views
Last Modified: 2010-04-07
Need the code to replace " with its ascii to avoid errors in a sql statement.
0
Comment
Question by:adamkushner
7 Comments
 
LVL 3

Expert Comment

by:Wasim_Haider
ID: 8164044
Please, send details
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8164095
Chr$(34) is the double quote
Chr$(39) is the single

is this what you're asking for?
0
 

Author Comment

by:adamkushner
ID: 8164249
"UPDATE Invoice SET LaborDescription = (" + Chr(34) + tempText + Chr(34) + ") WHERE InvoiceNumber = invoicenumber"

invoicenumber = key
tempText = textbox contents

I need to avoid errors due to double qoutes in the text box.  How do I go about this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
supunr earned 300 total points
ID: 8164375
Chage your Statement like below.

"UPDATE Invoice SET LaborDescription = """ & Replace(tempText, """", """ & chr(34) & """) & """ WHERE InvoiceNumber = invoicenumber"

Good Luck!
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 8164696
You don't have to change it to the ascii-code. Just replace ' by ''. This can be done by the easy statement replace

for example:
sql = "UPDATE Invoice SET LaborDescription = " & Replace(tempText, "'", "''") & "WHERE InvoiceNumber = " & invoicenumber

0
 
LVL 1

Expert Comment

by:Cliven
ID: 8165221


Chr$(34) is the double quote
Chr$(39) is the single

paste this code in vb module
Function QTrim(VVariant As Variant) As Variant
QTrim = Replace(Trim(VVariant), "'", "''")
End Function

'General sql statement using the Qtrim()
sql = "UPDATE Invoice SET LaborDescription = '" & Qtrim(Text1.text) & "' WHERE InvoiceNumber = " & invoicenumber


so every time you want to replace the ' to '' just use the qtrim(value) to do it.

easy and save time during the developing
0
 

Author Comment

by:adamkushner
ID: 8166115
This was the only answer that used double qoutes as I asked.

Cliven,
Could you show me how to use a function like that but for double qoutes? Simply replacing the single with double doesn't work.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question