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 IN ACCESS TABLE RECORDS

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
0
0
US
My asp is accessing data from an access DB table. A few of the records have apostrophe (') in them, which gives me a syntax error whenever I try to write them into my web pages.

Any feedbacks on how to handle this will be greatly appreciated.
 
using this function:

<script language=&quot;VBScript&quot; runat=&quot;Server&quot;>
FUNCTION CheckString (s, endchar)
pos = InStr(s, &quot;'&quot;)
While pos > 0
s = Mid(s, 1, pos) & &quot;'&quot; & Mid(s, pos + 1)
pos = InStr(pos + 2, s, &quot;'&quot;)
Wend
CheckString=&quot;'&quot; & s & &quot;'&quot; & endchar
END FUNCTION
</script>

you can call it when you are creating your select statement to replace the apostrophe like this:

sql = &quot;INSERT INTO Projects (&quot; &_
&quot;category, &quot; &_
&quot;priority) &quot; &_
&quot;VALUES ( &quot;
sql = sql & CheckString(Request(&quot;category&quot;),&quot;,&quot;)
sql = sql & CheckString(Request(&quot;priority&quot;), &quot;)&quot;)
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Projects&quot;
Conn.Execute(sql)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top