yronnen
asked on
Dataset.post method clears the dataset
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.
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.
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
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
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
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
ASKER
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.
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.
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
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
ASKER
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(Send er: 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(Send er: 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
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(Send
begin
Query1.Active := not Query1.Active;
end;
procedure TForm1.Button1Click(Sender
begin
if not (Query1.State in [dsInsert, dsEdit]) then
Query1.Insert;
end;
procedure TForm1.Button2Click(Sender
begin
if Query1.State in [dsInsert, dsEdit] then
Query1.Post;
end;
procedure TForm1.Button3Click(Sender
begin
Query1.Edit;
end;
procedure TForm1.Button4Click(Sender
begin
Query1.Delete;
end;
procedure TForm1.Button5Click(Sender
begin
Query1.ApplyUpdates;
end;
procedure TForm1.CheckBox2Click(Send
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!