Solved

Update SQL query

Posted on 2003-11-17
6
510 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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