The client application is written in Delphi using the DevExpress vcl , I connect to the MS SQL server. I connect to the database in the DataSourse ADOQuery .

Faced with this kind of problem:

Change the field value:

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

It seems to be changed and displayed in the grid (Changed by Avark to Yakovlev) link text

I run the 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; 

link text

And I see the old data (Uvarov became the avark as he was), that is, the field was enrolled in the grid, but there is no database. I can not understand what the problem is. However, if the filter is not run, the data is for some reason saved, and after applying the filter, nothing can be changed.

  • what tin grid itself is able to perfectly filter, and even more so cxGrid. why do you need a sql query at all? - Yura Ivanov
  • Maybe ..., the filter is needed in order to display all the data that meets the conditions of the filter from the database, and not just those that are now located in the cxGrid. But that is not the question. As I understand it, the problem occurs with dm.Tviezdi.Active: = false; and dm.Tviezdi.Active: = true; , disconnecting and connecting again to the database, but why does it not save? - G4us
  • When working with Sql queries, there are two options, in one case it creates a copy of the table and it is available only for viewing, in the second case no table is created and the data is editable, apparently you need to write a query with update, with the BDE components there was a SqlUpdate component, I set it up and the problem is solved, but how to implement ADO components? - G4us
  • Perhaps there is a certain function: DBMS.post; which makes the entry of all changes to the database. - IVsevolod

1 answer 1

The problem was solved quite simply. We add lines:

 DM.tviezdi.LockType:= ltBatchOptimistic 

or

 DM.tviezdi.LockType:= ltOptimistic 

Then I added a button in the window where the Grid is, and added to it:

 DM.Tviezdi.UpdateBatch(arAll); 

It all worked. Here is more detailed.