-2

I am using Delphi 2010 with TFIBDataset components.

I am facing a very strange issue, I have two TFIBDataset components called DS1 and DS2.

When I am trying to post the data in DS1 as below:

DS1.Post;

I get the error saying that "Dataset Not In Insert or Edit Mode...".

I faced such errors related to the datasets whose data I am trying to post, but this completely new issue I am facing.

Even though I tried to make DS2 in edit mode as below:

DS2.Edit;
DS1.Post;

Then also I am getting the same error.

Any clue ?

Vishal Tiwari
  • 739
  • 2
  • 12
  • 28
  • How does DS1 relate to DS2 that you are putting DS2 in edit mode to post on DS1? – Amir Rahimi Farahani Apr 22 '15 at 14:01
  • That is what I am also wondering, the issue is coming only when I say DS1.Post; and I get the error. I want to know what could be the causing issue. – Vishal Tiwari Apr 22 '15 at 14:02
  • You have to set DS1 in edit or insert mode before calling DS1.Post, by calling DS1.Edit or DS1.Insert – Amir Rahimi Farahani Apr 22 '15 at 14:04
  • Have you tried `DS1.Edit` before `DS1.Post`? – Uwe Raabe Apr 22 '15 at 14:04
  • Ya tried, same issue. – Vishal Tiwari Apr 22 '15 at 14:08
  • Can you show the code context of how/where you are using this? It is difficult to answer when not knowing how DS1 and DS2 link to each other. – Bernd Linde Apr 22 '15 at 14:26
  • 1
    Your code sets `DS2.Edit`, but tries to post to `DS1`. If you want to edit `DS1` and then post the changes, you need to use `DS1` in both operations. You can't edit one dataset and post to a different one. It's unclear what you're actually trying to do, because the code you've posted is so wrong. It's like saying "my left hand is soiled, but when I wash my right hand the left one doesn't get clean". You get the error because you're not editing and posting to the same dataset. There's no "strange issue"; it's simply totally wrong code that clearly makes no sense. – Ken White Apr 22 '15 at 14:40
  • @Ken: This is what is happening, code sharing is not possible because it is huge amount of code. That is why I am wondering when there is no relation between two datasets, why should I get the error ? – Vishal Tiwari Apr 22 '15 at 14:48
  • 2
    I've explained why. You **cannot** edit DS1 and then post to DS2. lf you want to edit DS1, then 'DS1.Edit; // change DS1 DS1.Post;`. If you want to edit DS2, then `DS2.Edit; // change DS2 DS2.Post;`. You can't `DS1.Edit; DS2.Post;`. You can only **post** the same dataset you've put in **edit** mode. This is plain common sense. *You cannot post changes to a dataset you've not put into edit mode.* I don't know how to say it more clearly than that, and I don't know how repeating it again and again will force you to actually read the words. – Ken White Apr 22 '15 at 18:47
  • Try putting break point on some kind of after post event, and see who is pulling dataset out of edit mode. Is dataset attached to grid control, or ds1 and ds2 are in master detail relationship..., you'll have to provide us with additional information, because nobody here is the magician who can see the future. – Bojan Čakarić Apr 22 '15 at 21:15
  • Let me explain, after detail code study I found that DS1 is a data set which is connected to DSC1 Datasource and this data source is connected to DS2 via Datasource property. So, when the "DS1.Post;" I get error. I just created a BeforePost event of DS2 dataset, then when the "DS1.Post;" is called the break point is coming in its BeforePost event, but actually this event is not created in the existing code. – Vishal Tiwari Apr 23 '15 at 10:57
  • I would like to know when we Post the data from the child dataset (DS1) then parent dataset's (DS2) would also try to post the data. FYI, when the breakpoint hits at BeforePost event of DS2 that time both datasets are in dsInsert mode. still there is an error. Am I missing something ? – Vishal Tiwari Apr 23 '15 at 10:57

2 Answers2

0

I got the code working by writing below code:

DS1.DisableContrils;
DS1.Post;
DS1.EnableContrils;

With Best Regards.

Vishal

Vishal Tiwari
  • 739
  • 2
  • 12
  • 28
  • How does this answer the question ? Ken has already explained what the problem is. YOu have not shown teh code where DS1 is in edit mode. – Rohit Gupta Jun 17 '15 at 02:13
0

I got the same issue and have doen the following to solve my problem:

 for I := 0 to  Datamodule1.ComponentCount - 1 do
 if Datamodule1.Components[I] is TADOTable then
  Begin
    if (TADOTable(datamodule1.Components[i]).State in [dsEdit, dsInsert]) then
     TADOTable(datamodule1.Components[i]).POST;
  End;

I hope this will help

Johann
  • 155
  • 7
  • 15