Problem inserting/updating table from a calculating field

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
galit
Posts: 19
Joined: Mon 12 Feb 2007 11:07

Problem inserting/updating table from a calculating field

Post by galit » Thu 09 Jun 2011 08:14

when I post dataset the changed calculated field is not updated
see my example:
dataset = GetDataSet('SELECT ISNULL(ALT1, '') ALT1, ALT2 FROM STOCK WHERE PARTNUMBER = 'TABLE')
dataset.Edit();
dataset.FieldByName(ALT1).AsString = 'new alt1';
dataset.FieldByName(ALT2).AsString = 'new alt2';
dataset.Post();

only field ALT2 is updated

also the ALT1 field is not allowed to get value. I get error "field 'ALT1' cannot be modified" after changing readonly property of this field Im allowed to set new value but as I said previosly this field is not posted

there is no restriction with dbExpress driver

AndreyZ

Post by AndreyZ » Thu 09 Jun 2011 13:49

Hello,

You cannot change the field value that is received as a result of expression, because in this case you don't work with the real column. SQL Server doesn't supply the information about the real name of such field and the name of a table that owns this field. To avoid the problem, you should use the following code:

Code: Select all

dataset = GetDataSet('SELECT ALT1, ALT2 FROM STOCK WHERE PARTNUMBER = 'TABLE') 
dataset.Edit(); 
dataset.FieldByName(ALT1).AsString = 'new alt1'; 
dataset.FieldByName(ALT2).AsString = 'new alt2'; 
dataset.Post();

Post Reply