Solved

Update SQL query

Posted on 2003-11-17
6
502 Views
Last Modified: 2010-04-05

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
0
Comment
Question by:dealclick
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Darth_helge
ID: 9762803
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
 
LVL 5

Expert Comment

by:Darth_helge
ID: 9762808
if the string is stored in a variable s do this:

AdoCommand.CommandText := 'update customer set CustomerType = ''' + s + ''' where rec = 99';
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 9762881
delphi provides a quotedstr-function

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

meikl ;-)

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9762894
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
 

Author Comment

by:dealclick
ID: 9762996

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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9763049
glad you got it work :-))

for Darth_helge,

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

meikl ;-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now