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
dealclickAsked:
Who is Participating?
 
kretzschmarCommented:
delphi provides a quotedstr-function

AdoCommand.CommandText := 'update customer set CustomerType = '+quotedstr(text)+' where rec = 99';

meikl ;-)

0
 
Darth_helgeCommented:
AdoCommand.CommandText := 'update customer set CustomerType = ''text'' where rec = 99';

two single quotes in a row before and after the text-string.
this should do the trick :=)

0
 
Darth_helgeCommented:
if the string is stored in a variable s do this:

AdoCommand.CommandText := 'update customer set CustomerType = ''' + s + ''' where rec = 99';
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
kretzschmarCommented:
but better would be to use a parameter like

AdoCommand.CommandText := 'update customer set CustomerType = :1 where rec = 99';
AdoCommand.Parameters[0].AsString := 'text';


not tested

meikl ;-)

0
 
dealclickAuthor Commented:

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.

;-)
0
 
kretzschmarCommented:
glad you got it work :-))

for Darth_helge,

i posted a q for you,
because your suggestion are also correct

meikl ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.