Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1999-06-30
Medium Priority
Last Modified: 2010-04-06
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?
Question by:Edukas
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 27

Expert Comment

ID: 1385416
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


Author Comment

ID: 1385417

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.
LVL 27

Expert Comment

ID: 1385418
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


Accepted Solution

pbaw earned 40 total points
ID: 1385419
Use the TDBNavigator component to control your inserts and deletes.

You can use tables with C/S.

Expert Comment

ID: 1385420
Forgot to mention.  You must set request live to be true otherwise the editing buttons will not be active on the navigator.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

670 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