Solved

Dataset.post method clears the dataset

Posted on 2003-11-15
8
287 Views
Last Modified: 2010-04-05
Hello.

I'm using Delphi 6 with BDE against Oracle in a native connection.
I'm doing the following scenario:
1. Insert a new record to a table, use POST to save it.
2. Go to edit mode and change some values in some fields.
3. Use the POST method to save the data.
4. The dataset is now empty. The record was gone (even though it is saved in
the database).

The problem happened in my application, but I've created a test application that simply adds new records to the database, and this behaviour remains.

Why running the POST method after edit causes the data to disappear from the
dataset?

Any ideas of how to solve this problem (running a query to select the record
I've just updated is not the answer I'm looking for :) )?

Thanks.

0
Comment
Question by:yronnen
8 Comments
 
LVL 7

Expert Comment

by:jconde
ID: 9758059
Can you post the code for the demo app ? ... the one that inserts the records and calls post.

At a glance, this sounds like a bug in the oracle driver.  Since I don't have access to Oracle, it will be much easier to deduce what's going on if you post some of your code!
0
 
LVL 3

Expert Comment

by:Mamouri
ID: 9759803
Hi!
perhaps your inserting in a detail record and master-detail fields are not set correctly!

BTW as jconde said you have to send your source code and table struction. then we can provide more information!

Regards
0
 
LVL 17

Expert Comment

by:geobul
ID: 9762466
Hi,

Does your dataset have a filter? Perhaps after modifying some fields (Edit then Post) your current record goes out of the filter scope.

Regards, Geo
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Author Comment

by:yronnen
ID: 9769957
Nope.

No filters.

I can even pinpoint the proble, it happens ONLY if you insert a record, post it, get to edit mode, do changes and post it again.
0
 
LVL 3

Expert Comment

by:Mamouri
ID: 9774254
Hi!

Please create a test project and copy the source code of main unit, the dfm code of main form and structure of database you are using!

Then people in EE can help more!

Regards
0
 
LVL 5

Author Comment

by:yronnen
ID: 9779441
here's a sample code that causes the same problems:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, DBTables;

type
  TForm1 = class(TForm)
    Database1: TDatabase;
    Query1: TQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    CheckBox1: TCheckBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    CheckBox2: TCheckBox;
    procedure CheckBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  Query1.Active := not Query1.Active;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not (Query1.State in [dsInsert, dsEdit]) then
    Query1.Insert;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if Query1.State in [dsInsert, dsEdit] then
    Query1.Post;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Query1.Edit;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Query1.Delete;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  Query1.ApplyUpdates;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  Query1.CachedUpdates := CheckBox2.Checked;
end;

end.



and the DFM:

object Form1: TForm1
  Left = 192
  Top = 110
  Width = 408
  Height = 322
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 24
    Top = 24
    Width = 320
    Height = 120
    DataSource = DataSource1
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object DBNavigator1: TDBNavigator
    Left = 24
    Top = 152
    Width = 320
    Height = 25
    DataSource = DataSource1
    Flat = True
    TabOrder = 1
  end
  object CheckBox1: TCheckBox
    Left = 56
    Top = 248
    Width = 97
    Height = 17
    Caption = 'Open'
    TabOrder = 2
    OnClick = CheckBox1Click
  end
  object Button1: TButton
    Left = 240
    Top = 192
    Width = 75
    Height = 25
    Caption = 'Insert'
    TabOrder = 3
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 240
    Top = 224
    Width = 75
    Height = 25
    Caption = 'Post'
    TabOrder = 4
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 320
    Top = 192
    Width = 75
    Height = 25
    Caption = 'Edit'
    TabOrder = 5
    OnClick = Button3Click
  end
  object Button4: TButton
    Left = 320
    Top = 224
    Width = 75
    Height = 25
    Caption = 'Delete'
    TabOrder = 6
    OnClick = Button4Click
  end
  object Button5: TButton
    Left = 240
    Top = 256
    Width = 75
    Height = 25
    Caption = 'ApplyUpdates'
    TabOrder = 7
    OnClick = Button5Click
  end
  object CheckBox2: TCheckBox
    Left = 56
    Top = 272
    Width = 97
    Height = 17
    Caption = 'CachedUpdates'
    TabOrder = 8
    OnClick = CheckBox2Click
  end
  object Database1: TDatabase
    AliasName = 'ADA_LIFE_DEV'
    DatabaseName = 'Sabi'
    LoginPrompt = False
    Params.Strings = (
      'SERVER NAME=ADADEV'
      'USER NAME=ADA_LIFE'
      'PASSWORD=artis')
    SessionName = 'Default'
    Left = 32
    Top = 200
  end
  object Query1: TQuery
    DatabaseName = 'Sabi'
    RequestLive = True
    SQL.Strings = (
      'SELECT * FROM A43')
    Left = 96
    Top = 200
  end
  object DataSource1: TDataSource
    DataSet = Query1
    Left = 136
    Top = 200
  end
end
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 10552768
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
(re-order part number xm34)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now