How to insert new record into query?
if I use DBgrid it's OK. I press <down> key
and insert new record automatically.
How I can do this when I use DBEdit components?
Query haven't INSERT method. Maybe it is necessary use TTable component for record inserting?
I use InterBase, CachedUpdates, Query.Live:=True;
But people says that in Client Server application
it is impossible to use TTable?
Who is Participating?
pbawConnect With a Mentor Commented:
Use the TDBNavigator component to control your inserts and deletes.

You can use tables with C/S.
hi Edukas,

>But people says that in Client Server application
>it is impossible to use TTable?
Thats not true

second you van perform inserts by using a TUpdateSQL-Compenent as UpdateObject of the query

here is a sample, which uses a TTable as master, a TQuery as Detail and a TUpdateSQL, which applys the changes for the Detail part (insert, delete, modify)

     here form as text

     object Form1: TForm1
       Left = 200
       Top = 112
       Width = 544
       Height = 375
       Caption = 'Form1'
       Font.Charset = DEFAULT_CHARSET
       Font.Color = clWindowText
       Font.Height = -11
       Font.Name = 'MS Sans Serif'
       Font.Style = []
       PixelsPerInch = 96
       TextHeight = 13
       object DBNavigator1: TDBNavigator
         Left = 128
         Top = 16
         Width = 240
         Height = 25
         DataSource = DataSource1
         TabOrder = 0
       object DBNavigator2: TDBNavigator
         Left = 100
         Top = 160
         Width = 240
         Height = 25
         DataSource = DataSource2
         TabOrder = 1
       object DBGrid1: TDBGrid
         Left = 24
         Top = 56
         Width = 477
         Height = 93
         DataSource = DataSource1
         TabOrder = 2
         TitleFont.Charset = DEFAULT_CHARSET
         TitleFont.Color = clWindowText
         TitleFont.Height = -11
         TitleFont.Name = 'MS Sans Serif'
         TitleFont.Style = []
       object DBGrid2: TDBGrid
         Left = 20
         Top = 200
         Width = 497
         Height = 133
         DataSource = DataSource2
         TabOrder = 3
         TitleFont.Charset = DEFAULT_CHARSET
         TitleFont.Color = clWindowText
         TitleFont.Height = -11
         TitleFont.Name = 'MS Sans Serif'
         TitleFont.Style = []
       object Table1: TTable
         Active = True
         DatabaseName = 'Nordwind'
         TableName = 'Master'
         Left = 20
         Top = 12
       object DataSource1: TDataSource
         DataSet = Table1
         Left = 60
         Top = 8
       object Query1: TQuery
         Active = True
         CachedUpdates = True
         AfterPost = Query1AfterPost
         AfterDelete = Query1AfterDelete
         DatabaseName = 'Nordwind'
         DataSource = DataSource1
         SQL.Strings = (
           'select * from Detail where MyID = :MyID order by MyDate desc')
         Params.Data = {01000100044D79494400030400010000000000}
         UpdateObject = UpdateSQL1
         Left = 16
         Top = 160
       object DataSource2: TDataSource
         DataSet = Query1
         Left = 44
         Top = 160
       object UpdateSQL1: TUpdateSQL
         ModifySQL.Strings = (
             'update detail set MyId = :MyID, MyDate = :MyDate,Remark = :Remar' +
             'k where MyID = :Old_MyId and MyDate = :Old_MyDate')
         InsertSQL.Strings = (
             'insert into detail (MyID,MyDate,Remark) values (:MyID,:MyDate,:R' +
         DeleteSQL.Strings = (
             'delete from detail where MyId = :Old_MyID and MyDate = :Old_MyDa' +
         Left = 72
         Top = 160

     here the unit

     unit sql_upd_acc_u;


       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
       Grids, DBGrids, ExtCtrls, DBCtrls, DBTables, Db;

       TForm1 = class(TForm)
         Table1: TTable;  
         DataSource1: TDataSource;
         Query1: TQuery;
         DataSource2: TDataSource;
         UpdateSQL1: TUpdateSQL;
         DBNavigator1: TDBNavigator;
         DBNavigator2: TDBNavigator;
         DBGrid1: TDBGrid;
         DBGrid2: TDBGrid;
         procedure Query1AfterPost(DataSet: TDataSet);
         procedure Query1AfterDelete(DataSet: TDataSet);
         { Private-Deklarationen }
         { Public-Deklarationen }

       Form1: TForm1;


     {$R *.DFM}

     procedure TForm1.Query1AfterPost(DataSet: TDataSet);

     procedure TForm1.Query1AfterDelete(DataSet: TDataSet);


     works fine

hope it helps a little

EdukasAuthor Commented:

thanks, but...

In your example you use only DBGrid's?
I asking about DBEdit's:
DBNavigator or I use Buttons for "Update", "Delete",
"Insert", "Cancel" records.
How I can press Insert on DBNavigator or Button "Insert"?
It's impossible.
hi Edukas,

It doesnt matter if it a grid or edit-controls

you can now easy use
the navigator buttons or
the methods

but be sure that you have a live-query
just try it out

Forgot to mention.  You must set request live to be true otherwise the editing buttons will not be active on the navigator.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.