Page 1 of 1

Problem inserting/updating table from a calculating field

Posted: Thu 09 Jun 2011 08:14
by galit
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

Posted: Thu 09 Jun 2011 13:49
by AndreyZ
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();