Hi,
I'm using Delphi 7 with SDAC TrailVersion of 3.80.0.31.
1. I have TMSQuery Component with an Insert statement on a form.
2. In FormCreate event, i'm executing Insert query.
3. And also i have an OnUpdateError event, where i'm throwing my own error message for duplicate value.
Now when i executed my project, first time a row got inserted into a table which is fine and i'm expecting the same.
Now again if i executed my project, it need to show an error message because i already inserted a row earlier with the same data.
I got the system error message at MSQuery.Execute statement. Stating that duplicate row. which is fine.
But i'm expecting that it fires OnUpdateError Event and throws an error message which i have written for Duplicate row. But it never calls the OnUpdateError Event..
Can you please give me hint/comments on this.
Thanks in advance
OnUpdateError event of TMSQuery is not firing
Hi,
I have followed below steps. Please correct me if i'm wrong anywhere.
In a form create event, i'm applying the changes i.e Insert into emp table. Where Empid already exits in a table.
Expected result: Duplicate id found error message which i have written in OnUpdateError event should fire. But it is not firing OnUpdateError event.
My CachedUpdates, UpdatesPending are True.
When 'MSQuery1.ApplyUpdates' statement is executed, it is calling 'OnUpdateRecord' event which is fine. Where i'm applying insert on
employee table. It is showing system generated duplicate error message when it executed 'MSUpdateSQL1.Apply(UpdateKind)'. After this it is coming back to FormCreate event and the cursor is moving to exception block and it never calls OnUpdateError Event.
1.
procedure TForm1.FormCreate(Sender: TObject);
begin
try
MSQuery1.Close;
MSQuery1.Open;
MSQuery1.Insert;
MSQuery1.Post;
if (MSQuery1.CachedUpdates and MSQuery1.UpdatesPending) then
begin
MSQuery1.ApplyUpdates;
end;
except
on E: Exception do
begin
raise; //Raise exception of duplicate error in OnUpdateError event.
end;
end;
2.
procedure TForm1.MSQuery1UpdateRecord(DataSet: TDataSet;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
//Getting system generated duplicate error message here
MSUpdateSQL1.Apply(UpdateKind); //UpdateKind = ukInsert
UpdateAction := uaApplied;
end;
3. OnUpateError event never calling???
procedure TForm1.MSQuery1UpdateError(DataSet: TDataSet; E: EDatabaseError;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
var
loop : integer;
count : integer;
RIerrorFound : boolean;
DupKeyFound : boolean;
begin
inherited;
RIerrorFound := false;
DupKeyFound := false;
If E is EMSError then
begin
count := EMSError(E).ErrorCount - 1;
For loop := 0 to count do
begin
CASE EMSError (E).errors[loop].OLEDBErrorCode OF
2398: raise Exception.Create('Duplicate code:
Please fix or delete and save again.');
End;
end;
end;
end;
UpdateAction := uaSkip;
end;
Note: I tried with SDAC trailer version 3.80.0.31 Demo Projects
CachedUpdates: Cached.dpr -> Main.pas -> MSQueryUpdateError() event. This event is not at all firing. I tried to fire this event in different ways. But it never fires. Please let us know the steps to fire this event.
I have followed below steps. Please correct me if i'm wrong anywhere.
In a form create event, i'm applying the changes i.e Insert into emp table. Where Empid already exits in a table.
Expected result: Duplicate id found error message which i have written in OnUpdateError event should fire. But it is not firing OnUpdateError event.
My CachedUpdates, UpdatesPending are True.
When 'MSQuery1.ApplyUpdates' statement is executed, it is calling 'OnUpdateRecord' event which is fine. Where i'm applying insert on
employee table. It is showing system generated duplicate error message when it executed 'MSUpdateSQL1.Apply(UpdateKind)'. After this it is coming back to FormCreate event and the cursor is moving to exception block and it never calls OnUpdateError Event.
1.
procedure TForm1.FormCreate(Sender: TObject);
begin
try
MSQuery1.Close;
MSQuery1.Open;
MSQuery1.Insert;
MSQuery1.Post;
if (MSQuery1.CachedUpdates and MSQuery1.UpdatesPending) then
begin
MSQuery1.ApplyUpdates;
end;
except
on E: Exception do
begin
raise; //Raise exception of duplicate error in OnUpdateError event.
end;
end;
2.
procedure TForm1.MSQuery1UpdateRecord(DataSet: TDataSet;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
//Getting system generated duplicate error message here
MSUpdateSQL1.Apply(UpdateKind); //UpdateKind = ukInsert
UpdateAction := uaApplied;
end;
3. OnUpateError event never calling???
procedure TForm1.MSQuery1UpdateError(DataSet: TDataSet; E: EDatabaseError;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
var
loop : integer;
count : integer;
RIerrorFound : boolean;
DupKeyFound : boolean;
begin
inherited;
RIerrorFound := false;
DupKeyFound := false;
If E is EMSError then
begin
count := EMSError(E).ErrorCount - 1;
For loop := 0 to count do
begin
CASE EMSError (E).errors[loop].OLEDBErrorCode OF
2398: raise Exception.Create('Duplicate code:
Please fix or delete and save again.');
End;
end;
end;
end;
UpdateAction := uaSkip;
end;
Note: I tried with SDAC trailer version 3.80.0.31 Demo Projects
CachedUpdates: Cached.dpr -> Main.pas -> MSQueryUpdateError() event. This event is not at all firing. I tried to fire this event in different ways. But it never fires. Please let us know the steps to fire this event.
OnUpdateError event handler is not called because changes are not applied by MSQuery1 component.
In OnUpdateRecord event handler you specified that record is already applied:that is why MSQuery1 does nothing.
If you want record to be applied by MSQuery1 then remove OnUpdateError event handler or modify it in following way:
In OnUpdateRecord event handler you specified that record is already applied:
Code: Select all
UpdateAction := uaApplied;
If you want record to be applied by MSQuery1 then remove OnUpdateError event handler or modify it in following way:
Code: Select all
procedure TForm1.MSQuery1UpdateRecord(DataSet: TDataSet;
UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
// your code
UpdateAction := TUpdateAction(uaDefault);
end;
Hi,
Thanks for your help...
Can you give me small code snipet or example to fire OnUpdateError event.
I want to know how to fire OnUpdateError event.
I tried with SDAC trailer version 3.80.0.31 Demo Projects CachedUpdates: Cached.dpr -> Main.pas -> MSQueryUpdateError() event.
It will be great help that if you could provide me steps to fire OnUpdateError event in Cached.dpr of SDAC demo projects.
Thanks for your help...
Can you give me small code snipet or example to fire OnUpdateError event.
I want to know how to fire OnUpdateError event.
I tried with SDAC trailer version 3.80.0.31 Demo Projects CachedUpdates: Cached.dpr -> Main.pas -> MSQueryUpdateError() event.
It will be great help that if you could provide me steps to fire OnUpdateError event in Cached.dpr of SDAC demo projects.
You are right. There is a bug in SDAC Trial. OnUpdateError event handler is never invoked.
Thank you for information. We have fixed the problem. This fix will be included in the next SDAC build.
Unfortunately we can't suggest you any temporary solution. SDAC Standard does not have such problem.
Please watch for announcements at the forum.
Thank you for information. We have fixed the problem. This fix will be included in the next SDAC build.
Unfortunately we can't suggest you any temporary solution. SDAC Standard does not have such problem.
Please watch for announcements at the forum.