Joey said:
Bob,
Not sure I understand your comments about not using dynamic sql. I
read the documents and it seems as if I do it the correct way.
USUALLY, I do not use a recordset to update variables. My current
code does, because it's old code and I never re-wrote it. Usually, I
do the following:
if request("submit")<> "" then
v1=Replace(Request.form("v1"), "'", "''")
v2=Replace(Request.form("v2"), "'", "''")
sql="update table set v1='" & v1 & "',v2='" & v2 & "' where id='1'"
conn.execute (sql)
Wait a minute. Earlier you showed this code:
Set RS = Server.CreateObject("ADODB.Recordset")
sqlUpdate = "SELECT * FROM ricprops WHERE propno='" & Request("id") &
"'"
RS.open sqlUpdate,Conn,1,3
RS("comments") = Replace(Request.form("comments"), "'", "''")
RS.Update
RS.Close
When updating a recordset field, do NOT escape (double up) the aprostrophe.
Change it to:
RS("comments") = Request.form("comments")
The only time you need to escape the apostrophe is when you are building
dynamic sql as in the update statement you show above.
Is that incorrect? Doing it this way, I still get the double
apostrophe.
I don't think so. Create a page with just this code in it:
<%
dim conn, sql, rs, input, output
input="it's nice"
set conn=createobject("adodb.connection")
conn.open "your connection string"
sql= "update ricprops set comments='" & _
Replace(input, "'", "''") & _
"WHERE propno=1"
conn.execute sql,,129
sql="select comments from ricprops WHERE propno=1"
set rs=conn.execute(sql,,1)
output=rs(0).value
rs.close:set rs=nothing
conn.close: set conn=nothing
%>
<html><body>
I guarantee this will contain only one apostrophe:<BR>
<textarea cols="30" rows="10"
name="comments"><%=trim(rs("comments"))%></textarea>
</body></html>
Run the page.
Bob Barrows