Delphi Error Dataset not in Insert or Edit Mode
Asked Answered
T

1

6

Objective:

  1. Click on the button on the TRxDBCombo to call a search box
  2. On Selecting the record from search box, the result is set as Field Value for the TComboEditBox and is posted in the TRxMemoryData Dataset

The Error:

Dataset not in Insert or Edit Mode appears the second time of calling this function

TDBEditBox1.SetFocus;
Form_Search:= TForm_Search.Create(Application);
with Form_Search do
  Begin
    showmodal;
    //Get Result from Database
    if trim(TempResult) <> '' then
      Begin
        TDBEditBox1.Field.Value := MResult;
      End;
  End;

The setup includes:

  1. A TJvDBGrid with the Data Source connected to a TDataSource
  2. The TDataSource is Connected to a TRxMemoryData
  3. A TRxDBComboEdit with its Data Source set to the TDataSource in step 2 above

Please assist

Three answered 26/6, 2013 at 6:25 Comment(2)
I'm not sure what the question is here. (Your control is probably named DBEditBox1 and not TBEditBox1, BTW.) The obvious solution is to put the dataset (the table attached to the DBEditBox1.Field) in either Insert or Edit mode before trying to assign a value to the field.Gnat
Sorry, but not so obvious... If you have a Data components in combination with a Grid or DBNavigator on the form you can get taken out of Edit or Insert mode without even knowing it until you get an error msg.Moralez
B
16

The error is coming because of the following line: TDBEditBox1.Field.Value := MResult; at this line your dataset is not in Insert or Edit mode. You can add following check to avoid this error:

if not (TDBEditBox1.DataSource.DataSet.State in [dsEdit, dsInsert]) then
begin
  TDBEditBox1.DataSource.DataSet.Edit;
  // Or TDBEditBox1. DataSource.DataSet.Insert; depending on the operation you are doing (Edit or Insert) 
end;
TDBEditBox1.Field.Value := MResult;
Bridgeboard answered 27/6, 2013 at 5:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.