Board index » delphi » ADO+Access=>"Inaccessible value" after "Append"

ADO+Access=>"Inaccessible value" after "Append"

I am using ADO Express to connect with a Microsoft Access database.  The
database contains several tables, and I am attempting to add data into one
of them.  This is an outline of my code:

function ADO_Access.RecordExists(const ID: integer): boolean;
begin
    Result := DBData.Locate('Sample ID', ID, []);
end;

procedure ADO_Access.AddRecord(const ID: integer);
begin
  DBData.Append;
  DBData.FieldByName(FieldNames[0]).AsInteger := ID;
  DBData.Post;
end;

procedure ADO_Access.AddData(ID: integer; Data: MasterDataRec): boolean;
begin
  if not RecordExists(ID) then
    AddRecord(ID);

  DBData.Edit;
  DBData.FieldByName(FieldNames[1]).AsFloat := Data.Value1;
  DBData.FieldByName(FieldNames[2]).AsFloat := Data.Value2;
  try
    DBData.Post;
  except
    on e:eDatabaseError do
      begin
        DBData.Cancel;
// If "AddRecord" has been called (and forever after that), I get an
"Inaccessible value" exception here.
        writeln(e.message);
      end;
    end;
end;

If the "AddRecord" procedure has been called, access to the database appears
to be shut off.  Before that, I am able to edit already-existing records
with facility.

By the way, in the "AddRecord" procedure, the value that is written to the
database is accepted by the database.  In other words, that procedure works,
but thereafter, nothing works.

Thanks in advance.

Rick Winterton

 

Re:ADO+Access=>"Inaccessible value" after "Append"


p.s.

DBData is a TADODataset object opened as follows:

  ADOConnection1 := TADOConnection.Create(Nil);
  ADOConnection1.LoginPrompt := false;
  ADOConnection1.Mode := cmShareDenyNone;

  { The ConnectionString is as follows:
    'Provider=Microsoft.Jet.OLEDB.4.0;
     Data Source=Drive\Path\MYDatabase.mdb;
     User ID=Admin;
     Persist Security Info=False' }

  ADOConnection1.ConnectionString := AccessProvider + ';' +
                                     AccessDataBase  + ';' +
                                     'User ID=Admin;'+
                                     PersistSecurityInfo;
  ADOConnection1.Open;

  DBData := TADODataset.Create(Nil);
  DBData.Connection := ADOConnection1;
  DBData.CursorType := ctStatic;
  DBData.CommandType := cmdText;
  DBData.CommandText := 'SELECT * FROM '+AccesstableName;
  DBData.Open;

Re:ADO+Access=>"Inaccessible value" after "Append"


I solved my problem.  Merely call "DBData.Requery" in the
ADO_Access.AddRecord procedure:

Quote
"Rick Winterton" <rwinter...@home.com> wrote in message

news:3a50a5ef$1_2@dnews...
Quote
> I am using ADO Express to connect with a Microsoft Access database.  The
> database contains several tables, and I am attempting to add data into one
> of them.  This is an outline of my code:

> function ADO_Access.RecordExists(const ID: integer): boolean;
> begin
>     Result := DBData.Locate('Sample ID', ID, []);
> end;

> procedure ADO_Access.AddRecord(const ID: integer);
> begin
>   DBData.Append;
>   DBData.FieldByName(FieldNames[0]).AsInteger := ID;
>   DBData.Post;

     DBData.Requery;  // updates the dataset list.
...

Other Threads