Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting records using ClientDataSet - works only with simple tables - why?

20 views
Skip to first unread message

Dobedani

unread,
Oct 5, 2011, 4:17:32 AM10/5/11
to
Dear All,

I've finally convinced my customer that we should replace BDE with
dbExpress. First database platform to target is MS Access, so I'm
using dbExpress driver for ODBC - see http://sourceforge.net/projects/open-dbexpress.
So far so good, but I've now come to the last hurdle. At one point, I
allow the user to save the results of analyses to separate tables in
the same Access database from which I derive data for analysis.

With the following code, I'm able to insert a record into a simple
table - first field is an ID and the 2nd field an integer for year -
so no SQL ;-)

Unfortunately, it does not work with more complicated tables! In that
case, an exception occurs: 'ODBC SqlState HY011, native error code 72,
[ODBC Microsoft Access Driver]Attribute cannot be set now' when I
reach the line with ApplyUpdates. I understand from some news posts
that I could have set the cursor location of the dataset to
'adUseClient' if only the dataset would be an ADO dataset. Is there an
equivalent for that in dbExpress? TIA

begin
try
...

// Open the appropriate table
if (not FDeleteFlag) or FUpdateFlag then
begin
Table := TSqlDataSet.Create(nil);
Table.SQLConnection := SQLConnection1;
Table.CommandType := ctTable;
Table.CommandText := TableName;
Table.SortFieldNames := 'RUN_ID';
Table.Open();
DataSetProvider1.DataSet := Table;
ClientDataSet1.SetProvider(DataSetProvider1);
ClientDataSet1.Open();
ClientDataSet1.Append();
WriteToRecord(aResult, ClientDataSet1);
ClientDataSet1.ApplyUpdates(0);
ClientDataSet1.Close();
Table.Close();
end;
except
...
end;
end;

0 new messages