Trying to modify read-only field.

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
tulu
Posts: 7
Joined: Tue 13 Mar 2007 13:48

Trying to modify read-only field.

Post by tulu » Tue 13 Mar 2007 14:27

I have a client data set populated using a stored procedure. Then the client data set is modified by user, but not written back. All worked OK under BDE but, after I switched to CoreLab, I started to get the read-only field error.

Although I set the individual field as .readonly := false, I still get the "Trying to modify read-only field." error.

The field is a calcuated field. If I modify the stored procedure, first calculate the field and write into a temporary table, then return with a join all works fine. Something like this:

create procedure spTest
as begin
// age read only here.
select ID, Name, Age+1 as Age from testtable
end

go

create procedure spTest
as begin
// age can be modified here.
declare @a table (id int, age int null)
insert into @a(id, age)
select ID, Age+1 as Age from testtable

select T.ID, T.Name, A.Age as Age
from testtable T
JOIN @a A ON A.ID = T.ID

end

But as you can see, this is a lot of work, and sometimes not even feasible.
Any suggestions?

jfpicard
Posts: 24
Joined: Tue 06 Dec 2005 21:17

Post by jfpicard » Tue 13 Mar 2007 20:03

Try to add an empty TMSUpdateSQL connected to your query; it may solve the problem.

tulu
Posts: 7
Joined: Tue 13 Mar 2007 13:48

Post by tulu » Wed 14 Mar 2007 08:19

Thanks for the reply.

The thing works like this:

a qry -> a provider -> many client data sets.

I fill each client dataset using the same qry/provider pair. I connected an update sql to my query object. But did not work. Also I have tried to turn cached updates on. It still does not work.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Wed 14 Mar 2007 13:44

You should assign the SQLInsert, SQLUpdate, SQLDelete properties with the INSERT, UPDATE, DELETE statements correspondingly and set the TField.ReadOnly property to False in the DataSet fields editor for all the fields you want to update.

tulu
Posts: 7
Joined: Tue 13 Mar 2007 13:48

Post by tulu » Wed 14 Mar 2007 15:25

Thanks. Just fixing the fields did the trick.

I did not need the sqls or update object or cached updates = true.

Previously, I was trying to fix the readonly := false on clientdataset, in vain.
Now I fix them in the originating query, (afteropen event), and cds recieves them as readonly = false.

It works. :)

Post Reply