BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cancelling an insert

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress)
View previous topic :: View next topic  
Author Message
Stewart Bourke
Guest





PostPosted: Thu Nov 13, 2003 12:31 am    Post subject: Cancelling an insert Reply with quote



D6 Ent, dbExpress, interbase 6

I have a CDS, DSP and Sql Dataset all linked in the correct manner.

I execute a CDS.insert, and subsequently decide I want to cancel the insert
before any fields are assigned values.

If I execute

CDS.Cancel
CDS.CancelUpdates

I always get a 'key violation'.

IS this the correct way to cancel an insert. At the time of carrying out
the cancel, the key fields will both be null, because no values have been
assigned.

Thanks,

Stewrat Bourke


Back to top
Bill Todd
Guest





PostPosted: Thu Nov 13, 2003 1:54 am    Post subject: Re: Cancelling an insert Reply with quote



On Thu, 13 Nov 2003 00:31:50 -0000, "Stewart Bourke"
<stewartbourke (AT) eircom (DOT) net> wrote:

Quote:
CDS.Cancel
CDS.CancelUpdates

If the new record has been inserted but not posted you do not need to
call CancelUpdates.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Stewart Bourke
Guest





PostPosted: Thu Nov 13, 2003 9:07 am    Post subject: Re: Cancelling an insert Reply with quote



Ok, I now have a really wierd one.

I took out the call to cancelupdates, and now simply have a cds.cancel.

However, when I call the cancel, the last row of the dataset is
duplicated....

procedure TdmMain.cdsCountryBeforePost(DataSet: TDataSet);
var ct: integer;
begin
if (trim(cdsCountryCtr_Code.AsString)='') and
(trim(cdsCountryCTR_TEXT.AsString)='') then
begin
cdsCountry.Cancel;
// cdsCountry.CancelUpdates;
end
else
begin
with cdsCountry do
begin
for ct:=0 to Fields.Count-1 do
Fields[ct].text:=UpperCase(Fields[ct].text);
end;
end;
end;

As you can see, the code simply checks to see if two fields are empty. IF
they are, I call the cancel. I know this is being executed because the
debugger traces into it. The wieird this is that as soon as I 'come back'
from the cancel operation, the last row in the dataset has been duplicated.

Would you have any suggestions?

Thanks,

Stewart Bourke

"Bill Todd" <no (AT) no (DOT) com> wrote

Quote:
On Thu, 13 Nov 2003 00:31:50 -0000, "Stewart Bourke"
[email]stewartbourke (AT) eircom (DOT) net[/email]> wrote:

CDS.Cancel
CDS.CancelUpdates

If the new record has been inserted but not posted you do not need to
call CancelUpdates.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)



Back to top
Bill Todd
Guest





PostPosted: Thu Nov 13, 2003 2:45 pm    Post subject: Re: Cancelling an insert Reply with quote

On Thu, 13 Nov 2003 09:07:59 -0000, "Stewart Bourke"
<stewartbourke (AT) eircom (DOT) net> wrote:

Quote:
I took out the call to cancelupdates, and now simply have a cds.cancel.

But you are calling Cancel in the BeforePost event. To stop the Post
from taking place you must also raise an exception. One way to do so
is to raise a silent exception by calling SysUtils.Abort.

procedure TdmMain.cdsCountryBeforePost(DataSet: TDataSet);
var ct: integer;
begin
if (trim(cdsCountryCtr_Code.AsString)='') and
(trim(cdsCountryCTR_TEXT.AsString)='') then
begin
cdsCountry.Cancel;
SysUtils.Abort; //<<<<<<<<<<<<< // cdsCountry.CancelUpdates;
end
else
begin
with cdsCountry do
begin
for ct:=0 to Fields.Count-1 do
Fields[ct].text:=UpperCase(Fields[ct].text);
end;
end;
end;

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.