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

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Japhar
Posts: 38
Joined: Thu 05 Oct 2006 04:22

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

Post by Japhar » Thu 09 Nov 2006 10:46

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...

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

Post by Jackson » Thu 09 Nov 2006 13:12

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;

Post Reply