P
P
Piligr1m2013-11-23 11:43:45
SQL
Piligr1m, 2013-11-23 11:43:45

Why can't I change the data in the database after Sql query?

The client application is written in Delphi using the DevExpress vcl libraries, I connect to the MS SQl server.
I connect to the database in the DataSourse ADoQuery bundle.
Faced this kind of problem:
I change the value of the field:

procedure TForm24.cxButton2Click(Sender: TObject);
    begin
    DM.tviezdi.edit;
    Dm.Tviezdi.FieldByName('Выезд').AsString  := 'Да';
    DM.Tviezdi.post;
    showmessage ('Аварком '+cxDBLookupComboBox3.Text+' назначен')
    end;

It seems to change and is displayed in cxGrid (Changed by avarkom to Yakovlev) I run the
f339b23059f41f98c80da59c9b074a45.png
filter:
procedure TForm13.cxButton5Click(Sender: TObject);
    begin
    dm.Tviezdi.Active := false;
    dm.Tviezdi.SQL.clear;
    Dm.Tviezdi.SQL.Add('set language Russian  set dateformat dmy ');
    // Dm.Tviezdi.SQL.Add('select *');
      Dm.Tviezdi.SQL.Add('select ');
      Dm.Tviezdi.SQL.Add('[dbo].[Дата последнего изменения состояния дела]([dbo].[БД].[№ Заявки]) [Дата последнего изменения состояния дела],');
      Dm.Tviezdi.SQL.Add('[dbo].[Просрочка состояния дела]([dbo].[БД].[№ Заявки])[Просрочено],');
      Dm.Tviezdi.SQL.Add('[dbo].[БД].[№ Заявки] idLoss,');
      Dm.Tviezdi.SQL.Add('*');
      Dm.Tviezdi.SQL.Add('FROM  [dbo].[БД]');
      Dm.Tviezdi.SQL.Add('LEFT JOIN [dbo].[Фото инфо]');
      Dm.Tviezdi.SQL.Add('ON [dbo].[Фото инфо].[№ заявки] = [dbo].[БД].[№ Заявки]');
      DM.Tviezdi.SQL.Add('WHERE 1=1');
      DM.Tviezdi.SQL.Add('-- find');
      Dm.Tviezdi.SQL.Add('AND([Дата осмотра]  >= '+#39+cxDateEdit1.Text+#39')');
    Dm.Tviezdi.SQL.Add('and ([Дата осмотра]  <= '+#39+cxDateEdit2.Text+#39')');
    Dm.Tviezdi.SQL.Add('Order By [№ Заявки] Desc');
    Dm.Tviezdi.ExecSQL;
    dm.Tviezdi.Active := true;
    end;

37e02a058616d2f36b8eec7e46c74b0b.png
And I see the old data (Uvarov became the avarcom as it was), that is, the field was registered in the grid, but not in the database. I can’t understand what the problem is. However, if the filter is not run, then the data is saved for some reason, and after applying the filter, change nothing works anymore.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Piligr1m, 2013-12-07
@Piligr1m

The problem was solved quite simply .... DM.tviezdi.LockType:= ltBatchOptimistic or ltOptimistic ,
then added a button in the window where Grid is, and added to it: DM.Tviezdi.UpdateBatch(arAll); and everything worked. There are more details
here www.da-soft.com/forums/freedac-osnovnoj-russkij/ra...

A
Alexey Skahin, 2013-11-23
@pihel

And how do you think the changes should go to the database?
To query with a changeable query, you need to tie up another update query in which to write insert, update and delete queries.
And after post, call applyupdates, which will already call update or insert depending on the mode.

A
Anatoly, 2013-11-23
@taliban

Dm.Tviezdi.FieldByName('Departure').AsString := 'Yes';
I suspect it's a getter, not a setter.

V
varus, 2013-12-07
@varus

And if the profiler looks at the requests that are generated in the database? This, as a rule, can lead to thoughts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question