<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I got a problem where I am trying to insert a value
into a database (ADO) using TAdoQeury which contains a single quote ( ' ) and
setting a parameter.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here goes :)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>I have a function written here which process's a sql command and sets the
permiater IF it's value is over -1 here is the
function.<BR><BR>//======================================<WBR>==========<WBR>====<BR>Procedure
SetSqlTextD( ADOQ : TADOQuery; sqltxt : string; value :
integer);<BR>Begin<BR> ADOQ.Active:=false;<BR>
ADOQ.SQL.Clear;<BR> ADOQ.SQL.Text := sqltxt;<BR><BR> If value
<> -1 then<BR> ADOQ.Parameters.ParamByName('SS').Value :=
value;<BR><BR> ADOQ.ExecSQL;<BR>
ADOQ.Close;<BR>End;<BR>//======================================<WBR>==========<WBR>====<BR><BR>And
you call it like this<BR>SetSqlTextD( AdoQ1, 'Update db SET field=" '+s+' "
WHERE id=:SS', 102);<BR><BR>OR<BR>SetSqlTextD( AdoQ1, 'Update db SET
field=" '+s+' " ', -1);<BR><BR>etc</DIV>
<DIV><BR>NOW<BR>if the second value is set to -1 then I can insert items with a
', if the second value is over -1 then I get the error?<BR>So with the examples
above, the first one would fail, the second one would work<BR>The error is,
Paramiter SS is not set.<BR></DIV>
<DIV>note that if value s --> smile's<BR>(single quote) then<BR>SetSqlTextD(
AdoQ1, 'Update db SET field=" '+s+' " ', -1);<BR>That works<BR><BR>SetSqlTextD(
AdoQ1, 'Update db SET field=" '+s+' " WHERE id=:SS', 102);<BR>That fails
with paramter SS not set<BR><BR><BR>if value s --> smile then<BR>(no quote)
then<BR>SetSqlTextD( AdoQ1, 'Update db SET field=" '+s+' " WHERE id=:SS',
102);<BR>works fine</DIV>
<DIV> </DIV>
<DIV>if value s --> smile''s then<BR>(two single quotes) then<BR>SetSqlTextD(
AdoQ1, 'Update db SET field=" '+s+' " WHERE id=:SS', 102);<BR>works fine
BUT puts smile''s in the database, not smile's</DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>