dealclick
asked on
Update SQL query
I'm using Delphi 5 with MS SQL and am trying to execute a update SQL query. Mostly I have been updating integer fields which has been no problem, but now I want to update a string field, which is causing me problems because of the single quotes needed in the SQL.
EG
AdoCommand.CommandText := 'update customer set CustomerType = 'text' where rec = 99;
Obvisouly the problem here is that the 'text' must be in single quotes (or somthing similar) but also the SQL stmt must be in single quotes as well (or something similar)
However I don't know what the something similar must be.
Simple I know, but I'm really stumped as to that I should use.
Thaniks
if the string is stored in a variable s do this:
AdoCommand.CommandText := 'update customer set CustomerType = ''' + s + ''' where rec = 99';
AdoCommand.CommandText := 'update customer set CustomerType = ''' + s + ''' where rec = 99';
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but better would be to use a parameter like
AdoCommand.CommandText := 'update customer set CustomerType = :1 where rec = 99';
AdoCommand.Parameters[0].A sString := 'text';
not tested
meikl ;-)
AdoCommand.CommandText := 'update customer set CustomerType = :1 where rec = 99';
AdoCommand.Parameters[0].A
not tested
meikl ;-)
ASKER
Thanks meikl, I've used the first solution cause it matches my simple mind, but accept that the param would maybe be a better way to go.
;-)
glad you got it work :-))
for Darth_helge,
i posted a q for you,
because your suggestion are also correct
meikl ;-)
for Darth_helge,
i posted a q for you,
because your suggestion are also correct
meikl ;-)
two single quotes in a row before and after the text-string.
this should do the trick :=)