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!

APOSTROPHE'S STILL BUGGING ME!! 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Thanks for the help with my apostrophe problem, folks, but could you explain more in detail as I am a beginner please.

The relevant code is below. What exactly do I do to it to sort out this apostrophe problem?

(The problem is that I can't insert a record with an apostrophe in it without an error message coming up or everything after the apostrophe being deleted).

Many thanks

James

set conn = server.createobject("adodb.connection")
conn.open "property"

SQLstmt = "INSERT INTO details (road,area,postcode,weekly_rental,number_bedrooms,location,furnished,list_text,detail_text,imageone,imagetwo)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & road & "',"
SQLstmt = SQLstmt & "'" & area & "',"
SQLstmt = SQLstmt & "'" & postcode & "',"
SQLstmt = SQLstmt & "'" & weekly_rental & "',"
SQLstmt = SQLstmt & "'" & number_bedrooms & "',"
SQLstmt = SQLstmt & "'" & location & "',"
SQLstmt = SQLstmt & "'" & furnished & "',"
SQLstmt = SQLstmt & "'" & list_text & "',"
SQLstmt = SQLstmt & "'" & detail_text & "',"
SQLstmt = SQLstmt & "'" & imageone & "',"
SQLstmt = SQLstmt & "'" & imagetwo & "'"
SQLstmt = SQLstmt & ")"

Set RS = conn.execute(SQLstmt)
If err.number>0 then
response.write &quot;VBScript Errors Occured:&quot; & &quot;<P>&quot;
response.write &quot;Error Number=&quot; & err.number & &quot;<P>&quot;
response.write &quot;Error Descr.=&quot; & err.description & &quot;<P>&quot;
response.write &quot;Help Context=&quot; & err.helpcontext & &quot;<P>&quot;
response.write &quot;Help Path=&quot; & err.helppath & &quot;<P>&quot;
response.write &quot;Native Error=&quot; & err.nativeerror & &quot;<P>&quot;
response.write &quot;Source=&quot; & err.source & &quot;<P>&quot;
response.write &quot;SQLState=&quot; & err.sqlstate & &quot;<P>&quot;
end if
 
Hi James,

Try this...

Just pass all your variables through the function.

Good Luck.

Al

**********************************

Function cleansql(strValue)
Dim strTemp
strTemp = strValue
Do Until InStr(1, strTemp, &quot;'&quot;) = 0
strTemp = Left(strTemp, InStr(1, strTemp, &quot;'&quot;) - 1) & Right(strTemp, Len(strTemp) - InStr(1, strTemp, &quot;'&quot;))
Loop
Do Until InStr(1, strTemp, Chr(34)) = 0
strTemp = Left(strTemp, InStr(1, strTemp, Chr(34)) - 1) & Right(strTemp, Len(strTemp) - InStr(1, strTemp, Chr(34)))
Loop
cleansql = strTemp
end function


SQLstmt = SQLstmt & &quot;'&quot; & cleansql(road) & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & cleansql(area) & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & cleansql(postcode) & &quot;',&quot;

******************************** [sig][/sig]
 
All that string manipulation and temp variable storage is expensive. Just use the built in replace function.

Function cleansql(strValue)
cleansql = replace(strValue,&quot;'&quot;,&quot;''&quot;)
End Function
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top