Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing apostrophes in text box

Status
Not open for further replies.

GWPhoenix

IS-IT--Management
Jun 26, 2001
32
0
0
US
I have a large form (about 20 fields) in which to update and insert new recordsets. The database is not accepting the apostrophe value as part of a string.

I am familiar with the code:

Code:
Value = replace(value,"'","''")
where "value" was the only possible property to be updated in a table.


But my question is:

Do I need to insert this line of code for each individual textbox and textarea on my update and insert forms?

 
create a function and when you send the insert statement or update statement apply this function to each value
 
gwphoenix,

There are a couple of options here.

1. You can do it for text boxes that you believe might have an apostrophe.

2. There is an option in SQL server to set QUOTED IDENTIFIER.

When SET QUOTED_IDENTIFIER is OFF (default), literal strings in expressions can be delimited by single or double quotation marks. If a literal string is delimited by double quotation marks, the string can contain embedded single quotation marks, such as apostrophes.



fengshui_1998
 
Thanks, Feng. Problem is, this is an Access Database.
 
gwphoenix,

Ah, yes, I assume too much! You probably have to replcae the singe quotes with double quotes. But then, so does everyone else!

fengshui_1998
 
Here is an example of a function!

Function ChkStr(string)
ChkStr = Replace(string, "'", "''")
End Function

Function being called before adding to database!
ChkStr(Request.Form("Specifications"))


angst11
 
Thanks, angst! That will work great. I guess you can tell I'm not the most adept person at this stuff....
 
I understand that if you replace the ' with a " it will fit into the database better.

However, if I was to response.write it onto a page from the database, won't it display:

Michael"s contacts

Will I have to convert it back for display purposes?
 
On my program, it writes Michael"s contacts when I have it display the executed SQL statement, but when I go to view the recordset itself, it's fine.
 
angst11,

Why call a function with the same function?

Function ChkStr(string)
ChkStr = Replace(string, "'", "''")
End Function

Is the same as...

ChkStr = Replace(string, "'", "''")

In my opinion, you do not need to call ChkStr if all you're doing is the same function. Might as well access it directly and not waste CPU cycles.

fengshui_1998


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top