Solved

Update SQL query

Posted on 2003-11-17
6
509 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
Delphi Dbf export problem to a Visual Foxpro application 6 207
select query - oracle 16 100
Firemonkey webbrowser scrollbars ? 1 50
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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