Page 1 of 1

Settting External Value to TMSQuery is not happing in Licenced Version of SDAC

Posted: Thu 09 Nov 2006 10:46
by Japhar
Hi,

We have an licenced SDAC 3.80.0.32 version.

Value for persistenc field is not get set in OnUpdateRecord event.

1. I have a form with TMSConnection, TMSQuery, TMSUdateSQL, Save button.

2. In a TMSQuery i have below select statement
"Select empid, empname from emp"

Values in DB are:
empid: 1
empname: abc

3. I set TMSQuery.UpdateObject=MSUpdateSQL in Object inspector of TMSQuery.

4. TMSUpdateSQL.InsertSQL property had below insert statement

Insert into emp (empid, empname) values (:empid,:empname)

5. Now i clicked on the Save button and i executed below code.

MSQuery.Database.StartTransaction;
MSQuery.ApplyUpdates; //It goes to OnUpdateRecord event
MSQuery.Database.Commit;

6. For MSQuery i have OnUpdateRecord event where i'm setting empname from 'abc' to 'xyz' before i do commit.

if not(DataSet.State in [dsEdit, dsInsert]) then
begin
DataSet.Edit;
End;

//Setting new value here
DataSet.FieldByName('empname').AsString := 'xyz';

case (UpdateKind) of
ukInsert:
begin
MedicUpdateSql1.Apply(ukInsert);
UpdateAction := uaApplied;
end
end;

My expected result is: I want to insert below values in emp table
empid: 1 (which is same as selected)
empname: xyz (which i'm overwritting)

But the value which i'm overwritting in OnUpdateEvent is not happening.
I tried many time but no luck. It always taking the same value which i have selected in select statement and inserting into emp table.

How can i overwrite the query field value??? Please suggest me how to overcome this situation by using MSUpdateSQL component. Becuase my project is using this component almost for all DML operations.

Thanks in advance...

Posted: Thu 09 Nov 2006 13:12
by Jackson
Do you really need CachedUpdates mode?
If it is so then please see CachedUpdates demo otherwise see UpdateSQL demo for more information.
In most cases the following code is enough to insert new record to a table

Code: Select all

  MSQuery1.Insert;
  MSQuery1.FieldByName('empname').AsString := 'xyz';
  MSQuery1.Post;