• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

How to use update(SQL) statement in delphi?

I want to use a SQL statement like this:
'update fixasset set assetstatus='0' where assetstatus='F' '
I want to write it in delphi program. I don't want to use store procedure. I write it in TQuery but it not work. Can you tell the details of how to do so???
0
keynes
Asked:
keynes
  • 3
  • 2
  • 2
  • +3
1 Solution
 
rwilson032697Commented:
You need to use the ExecSQL method...

Perhaps you could post you code that does no work?

Cheers,

Raymond.

0
 
yk030299Commented:
What is the query.CacheUpdates?
0
 
simonetCommented:
When using that kind of statement in a TQuery component, you must call it by issuing:

Query1.ExecSQL;

It will not work if you call "Query1.Open" or "Query1.Active := true".

Are you getting any error messages?

Alex
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
keynesAuthor Commented:
I use execsql.
But it returned a error message
'Table is read-only.'
0
 
kretzschmarCommented:
hi keynes,

execsql is the way, after fired you can get with the property rowsaffected how much records are updated.

>'Table is read-only.'
what database do you use?

meikl
0
 
yk030299Commented:
did update priv of Table fixasset grant ti user?
0
 
RBertoraCommented:
I want to use a SQL statement like this:
'update fixasset set assetstatus='0' where assetstatus='F' '
I want to write it in delphi program. I don't want to use store procedure. I write it in TQuery but it not work. Can you tell the details of how to do so???

This will work in all cases but one:

uses DB, DBTables;

procedure TForm1.Button1Click(Sender: TObject);
var
  TempQuery : TQuery;
begin
  TempQuery := TQuery.Create(Form1);
  TempQuery.DatabaseName := 'YourBDEAliasName';
  TempQuery.Sql.Clear;
  TempQuery.Sql.Add('update fixasset set assetstatus= ''0'' where assetstatus=''F'' ');
  TempQuery.ExcecSql;
end;

It wont work if you have a clustered index on more than the assetstatus field... you should remove the clustered index if you want this statement to work, alternatively you should include the entire index in your where clause.

cheers,
Bert.





0
 
keynesAuthor Commented:
Thanks everybody.
0
 
rwilson032697Commented:
Could you tell us what you needed to do to fix it?

Seems to me RBertora's answer did not contribute to the information already supplied by other experts...

Cheers,

Raymond.
0
 
simonetCommented:
Ditto.

keynes, why did you accept RBertora's answer since all he/she said had already been said by other experts?

Alex
0
 
simonetCommented:
Keynes, did you read me question?
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.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now