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

2
  • 1
    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.
    – Ken White
    Jun 26, 2013 at 13:18
  • 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.
    – TheSteven
    Jan 13, 2014 at 0:59

1 Answer 1

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.