|
-
Dec 19th, 2001, 12:08 PM
#1
Thread Starter
Addicted Member
Apostrophe Error
I am using the following code to submit values to a database. How can I adjust the code to allow information with apostophes to be allowed without messing up the SQL statement? (Using VBScript)
function UpdateNearestRelative()
appid = session("appID")
sqlUpdateApplicant = "Update ApplicantInfo set"
sqlUpdateApplicant = sqlUpdateApplicant & " NearRelative = '" & Request.Form("txtNRName") & "', "
sqlUpdateApplicant = sqlUpdateApplicant & " R_Address = '" & Request.Form("txtNRAddress") & "', "
sqlUpdateApplicant = sqlUpdateApplicant & " R_City = '" & Request.Form("txtNRCity") & "', "
sqlUpdateApplicant = sqlUpdateApplicant & " R_State = '" & Request.Form("txtNRState") & "', "
sqlUpdateApplicant = sqlUpdateApplicant & " R_Zip = '" & Request.Form("txtNRZip") & "', "
sqlUpdateApplicant = sqlUpdateApplicant & " R_Phone = '" & Request.Form("txtNRPHAreaCode") & Request.Form("txtNRPHPrefix") & Request.Form("txtNRPhNum") & "' "
sqlUpdateApplicant = sqlUpdateApplicant & " where ApplID = " & appid
Conn.Execute(sqlUpdateApplicant)
end function
Thanks!
Normal is boring...
 smh 
-
Dec 19th, 2001, 12:12 PM
#2
Addicted Member
Use the replace function to replace one single quote with two single quotes for each string value going into your insert statement
Code:
strSomeStrimg = Replace(strSomeStrimg, "'", "''")
Wydok
"It would appear that we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."
-John Von Neumann ca. 1949
-
Dec 19th, 2001, 12:14 PM
#3
Frenzied Member
Code:
strSQL = strSQL & Replace(strSomeValue, "'", "''")
You have to escape apostrophe's in SQL with another apostrophe. There is a thread about posting O'Something names.
Edit: Sorry, I got bored and kind of felt my code sample might be misleading, so I edited it.
Last edited by CiberTHuG; Dec 19th, 2001 at 12:29 PM.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Dec 19th, 2001, 12:14 PM
#4
Frenzied Member
Yeah, as Wydok said.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Dec 19th, 2001, 12:26 PM
#5
Thread Starter
Addicted Member
Normal is boring...
 smh 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|