How to access the nested table in BeforeUpdataReco |
尚未結案
|
kylixyao
一般會員 發表:10 回覆:11 積分:4 註冊:2003-11-20 發送簡訊給我 |
I have one to many tables master and detail.the detail table reference the
MasterId of master table as foreign key.I want to assign MasterId value for
detail table as the same value with ID in mastertable in BeforeUpdateRecord
event.But How can I access the nested detail table?
I use the following code:
with DeltaDs do
begin
if UpdateKind=ukInsert then
begin
Fieldbyname('ID').NewValue:=123;//assign master table's ID
while not TDatasetField(FieldbyName('detail')).NestedDataset.Eof do
begin
TDatasetField(FieldbyName('detail')).NestedDataset.FieldByName('MasterId').NewValue:=123;//loop to assign detail table's MasterID
TDatasetField(FieldbyName('detail')).NestedDataset.Next;
end;
end;
end;
but ApplyUpdates works fail.WHY?
|
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
kylixyao good day:
引言: with DeltaDs do begin if UpdateKind=ukInsert then begin Fieldbyname('ID').NewValue:=123;//assign master table's ID while not TDatasetField(FieldbyName('detail')).NestedDataset.Eof do begin TDatasetField(FieldbyName('detail')).NestedDataset.FieldByName('MasterId').NewValue:=123;//loop to assign detail table's MasterID TDatasetField(FieldbyName('detail')).NestedDataset.Next; end; end; end;in red code: you must one time one assign and that be transaction
------
====================== 昏睡~ 不昏睡~ 不由昏睡~ |
speedup
資深會員 發表:19 回覆:259 積分:280 註冊:2003-07-04 發送簡訊給我 |
引言: I have one to many tables master and detail.the detail table reference the MasterId of master table as foreign key.I want to assign MasterId value for detail table as the same value with ID in mastertable in BeforeUpdateRecord event.But How can I access the nested detail table? I use the following code: with DeltaDs do begin if UpdateKind=ukInsert then begin Fieldbyname('ID').NewValue:=123;//assign master table's ID while not TDatasetField(FieldbyName('detail')).NestedDataset.Eof do begin TDatasetField(FieldbyName('detail')).NestedDataset.FieldByName('MasterId').NewValue:=123;//loop to assign detail table's MasterID TDatasetField(FieldbyName('detail')).NestedDataset.Next; end; end; end; but ApplyUpdates works fail.WHY?When you update NestedTable ,if your delta contain both 1 master record and 3 detail reocrds,then BeforeUpdateRecord will call 4 times ,so you may change your code as with DeltaDs do if UpdateKind=ukInsert then begin //DataSetField is nil means that delta is Master's delta if DataSetField = nil then Fieldbyname('ID').NewValue:=123 else//Otherwise the delta is Detail's Delta FieldByName('MasterId').NewValue:=123; end; end;混心雜欲 棄修身~唉
------
唉~ |
kylixyao
一般會員 發表:10 回覆:11 積分:4 註冊:2003-11-20 發送簡訊給我 |
|
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
kylixyao good day: I don't know cadre of your project !
so,clued in my way! first
you must ascertain that is event time.
then
in BeforeUpdateRecord (Timing)
引言: with DeltaDs do begin if UpdateKind=ukInsert then begin //call function to assign master table's ID and result ID //this function must be transaction (do not fail) { while not TDatasetField(FieldbyName('detail')).NestedDataset.Eof do begin TDatasetField(FieldbyName('detail')).NestedDataset.FieldByName('MasterId').NewValue:=123;//loop to assign detail table's MasterID TDatasetField(FieldbyName('detail')).NestedDataset.Next; end; }//this code is loop to Insert of self,so in BeforeUpdateRecord it's call again end; end;
------
====================== 昏睡~ 不昏睡~ 不由昏睡~ |
kylixyao
一般會員 發表:10 回覆:11 積分:4 註冊:2003-11-20 發送簡訊給我 |
|
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |