全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1512
推到 Plurk!
推到 Facebook!

How to access the nested table in BeforeUpdataReco

尚未結案
kylixyao
一般會員


發表:10
回覆:11
積分:4
註冊:2003-11-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-20 08:44:27 IP:202.110.xxx.xxx 未訂閱
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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-20 09:55:59 IP:61.221.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-11-20 10:09:46 IP:61.224.xxx.xxx 未訂閱
引言: 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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-11-20 10:10:36 IP:202.110.xxx.xxx 未訂閱
pls tell me how can I code in detail?thanks.
ko
資深會員


發表:28
回覆:785
積分:444
註冊:2002-08-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-11-20 11:15:37 IP:61.221.xxx.xxx 未訂閱
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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-11-20 11:30:47 IP:202.110.xxx.xxx 未訂閱
Thanks KO,thanks Speedup!
Ktop_Robot
站務副站長


發表:0
回覆:3511
積分:0
註冊:2007-04-17

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-04-30 13:45:07 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-05-19 10:23:16
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!