Solved

Dataset.post method clears the dataset

Posted on 2003-11-15
8
289 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

823 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