Re: SQL Syntax for a single quote in a string.
- From: George Wei <nobody@xxxxxxxxx>
- Date: 23 Aug 2006 00:57:45 -0700
"lsg" <sgling07@xxxxxxxxx> wrote in
news:44ebff25$1@xxxxxxxxxxxxxxxxxxxxxx:
Hi,
I don't know how to write a syntax in SQL if there is a quote mark in
a string. Example :
Str := 'Sawal Afa'at'; <--- a'a
...
Add('update tbl set name='''+str+''''); ---> i used 3 single
quote on both sides. .... etc
this statement will give me error.
Can someone assist me how to solve this problem? Thanks in advance
Regards,
lsg
Try this:
Str := 'Sawal Afa''at'
But the suggested method is to use a parameter. For example:
var
cmd: TADOCommand;
begin
cmd := TADOCommand.Create(aConnection);
try
cmd.CommandText := 'update tbl set name=:1';
with cmd.Parameters.AddParameter do
begin
DataType := ftString;
Direction := pdInput;
Value := 'Sawal Afa''at';
end;
cmd.Execute;
finally
cmd.Free;
end;
end;
George
.
- Follow-Ups:
- Revision
- From: George Wei
- Revision
- References:
- Prev by Date: Re: Problems with ADO and Multithreading: List Index Out Of Bounds
- Next by Date: Revision
- Previous by thread: SQL Syntax for a single quote in a string.
- Next by thread: Revision
- Index(es):
Relevant Pages
|