views:

814

answers:

2

I am currently testing with:

  1. A SQLConnection which is pointed towards an IB database.
  2. A SQLDataset that has a SQLConnection field set to the one above.
  3. A DatasetProvider that has the SQLDataset in (2) as its Dataset field value.
  4. A ClientDataset, with the ProviderName field pointing to the provider in (3).

I use the following method (borrowed from Alister Christie) to get the data...

function TForm1.GetCurrEmployee(const IEmployeeID: integer): OleVariant; 
const 
  SQLSELEMP = 'SELECT E.* FROM EMPLOYEE E WHERE E.EMPLOYEEID = %s'; 
begin 
  MainDM.SQLDataset1.CommandText := Format(SQLSELEMP, [Edit1.Text]); 
  Result := MainDM.DataSetProvider1.Data; 
end;

Which populates the DBGrid with just one record. However, when I manually edit the record, click on Post, then try to commit the changes, using

MainDM.ClientDataset1.ApplyUpdates(0); // <<<<<<

It bombs, with the message "SQLDataset1: Cannot modify a read-only dataset."

I have checked the ReadOnly property of the Provider, and of the ClientDataset, and the SQL has no joins.

What could be causing the error?

A: 

Check the LiveMode property of the TIBDataSet.

eed3si9n
+2  A: 

It appears that your ClientDataSet.Data property is being populated from the Data property of the DataSetProvider. With the setup you described, you should be able to simply call ClientDataSet.Open, which will get the data from the DataSetProvider.

BTW, the default behavior of the DataSetProvider when you call the ClientDataSet.ApplyUpdates method is to send a SQL query to the connection object, and not the DataSet from which the data was obtained (assuming a homogeneous query). Make sure that your DataSetProvider.ResolveToDataSet property is not set to true.

Finally, on an unrelated note, your code above appears to be open to a SQL injection attack (though I have not tested this). It is safer to use a parameter to define the WHERE clause. If someone enters the following into Edit1 you might be in trouble (assuming the InterBase uses the drop table syntax): 1;drop table employee;

Cary Jensen
+1 for a great answer, and so glad to see you here. It'll be fantastic to have you contributing to SO!
Argalatyr