As an ex Delphi person, I’ve enjoyed (!) the migration to RemObjects. Much of the re-learning has been beneficial in bringing me closer to the underlying Dot Net principles, (and freeing me from some of the Delphi peculiarities!).
However, trying to manage the Database read/add/edit/delete has been a nightmare. What was simple in Delphi ADO seems to be massively complex. Even doing extensive reviews on the web fails to reveal a simple principle. There are numerous postings from people having problems doing “simple” deletes/updates.
In my Delphi stuff, I had a small number of tailored routines that did all I needed. In RemObjects I have attempted to do the same, but I have repeatedly found that that they don’t work in individual circumstances.
I know this is not a RemObjects problem, so forgive me for the rant. But if anyone can point me to a definitive source for a standard database access/update approach I would be very grateful!
As an example, my latest problem is a routine which deletes the rows in a specified table, then updates the underlying database with that change.
For a number of my tables in an Access database, this works fine, but in one table it fails with the famous “Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.”.
And yes it does have a primary key,
The relevant code is:
method clsDB.SetDBTableForUpdates(pTableNameStr: String; var pOleDbAdapt: System.Data.OleDb.OleDbDataAdapter; var pDTable: System.Data.DataTable);
begin
var cb := new System.Data.OleDb.OleDbCommandBuilder(pOleDbAdapt);
pOleDbAdapt.UpdateCommand := cb.GetUpdateCommand;
pOleDbAdapt.InsertCommand := cb.GetInsertCommand;
var DSet := new System.Data.DataSet;
pOleDbAdapt.Fill(DSet, pTableNameStr);
pDTable := DSet.Tables[pTableNameStr];
end;
method clsDB.DBTableDeleteAll(pTableNameStr: String);
begin
var OleDbAdapt := new System.Data.OleDb.OleDbDataAdapter('select * from ’ + pTableNameStr, clsVariables.TheDBOleDbConn);
var TheDTable := new System.Data.DataTable;
clsDB.SetDBTableForUpdates(pTableNameStr, var OleDbAdapt, var TheDTable);
var cm := TheDTable.Rows.Count - 1;
if cm = -1 then exit;
var c: Integer;
for c := 0 to cm do
begin
TheDTable.Rows[c].Delete;
end;
OleDbAdapt.Update(TheDTable);
end;
I may be me missing something obvious, in which case I apologise.
Any help/advice/derision () would be very welcome.