 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Stewart Bourke Guest
|
Posted: Thu Nov 13, 2003 12:31 am Post subject: Cancelling an insert |
|
|
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
|
Posted: Thu Nov 13, 2003 1:54 am Post subject: Re: Cancelling an insert |
|
|
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
|
Posted: Thu Nov 13, 2003 9:07 am Post subject: Re: Cancelling an insert |
|
|
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
|
Posted: Thu Nov 13, 2003 2:45 pm Post subject: Re: Cancelling an insert |
|
|
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 |
|
 |
|
|
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
|
|