2012-04-17 7 views
0

に子レコードを保存し、私はこの質問を何度も求められている実感 - と私は/読んだことがあると思いますそれらの多くを捜索 - と私は私が見つけたすべての提案を確認するために非常に懸命に試みている -問題一見のデータベース

おそらくもう一組の目が必要なのでしょうか?

問題は次のとおりです。 私はマスターテーブルと2つの詳細テーブルを持っています。それらは、データベースとまったく同じ関係、キー/ FKフィールド/タイプのデータソースと同じように定義されています。

私はテーブルに手動でデータを入力することができます。クエリを実行すると期待される結果が得られます(左への結合など)。また、正しい親レコードに結合されたアプリケーションでレコードを正しく表示できます。

ただし、これらのテーブル/ BindingSourcesのいずれかが正しく動作しています。 私は見て知っているどこでも見て、違いを見ることができない?

BargeDetailsテーブルバインディングソースは完全に機能します。 ShiftDeadTimeはレコードをデータベースに保存/挿入しません。

私はcheckedingとbindingsource.count = 1となり、基になるbindingsource.currentは期待値を持っています。

SQLトレースは、挿入/更新の試行を示していません。

私はVisual Studio 2010、ADO.NET、.NET 4、WinForms、およびSQL Server 2008を使用しています。 データソースはデザイナを最初に使用するコードではなく、設計されています。 正確なデータソース/ datamember = FKを指すように詳細バインディングソースを変更しました。

私の_Load()では、ta.fill()の順序は一見正しいと思います。

private void frmShiftReport_Load(object sender, EventArgs e) 
    { 
     this.shiftsTableAdapter.Fill(this.dsShiftReport.Shifts); 
     this.shiftDeadTimeTableAdapter.Fill(this.dsShiftReport.ShiftDeadTime);    
     this.bargeDetailTableAdapter.Fill(this.dsShiftReport.BargeDetail); 

     this.vw_BargeLookupTableAdapter.Fill(this.dsShiftReport.vw_BargeLookup); 
     this.vw_CommodityLookupTableAdapter.Fill(this.dsShiftReport.vw_CommodityLookup); 
    } 

バインディングソースは同じように設定されているようです。私は似た/正しいEndEdit()sおよびすべて更新を(持っているように見える私のクリック/保存したイベントで

shiftDeadTimeBindingSource

datasource = shiftsBindingSource1 
datamember = FK_ShiftDeadTime_Shifts 

bargeDetailBindingSource

datasource =  shiftsBindingSource1 
datamember =  FK_BargeDetail_Shifts 

dgShiftDeadTime

datasource = shiftDeadTimeBindingSource 

);

 // barge details 
    private void shiftsBindingNavigatorSaveItem_Click(object sender, EventArgs e) 
    { 
     this.Validate(); 
     this.shiftsBindingSource1.EndEdit(); 
     this.bargeDetailBindingSource.EndEdit(); 

     this.tableAdapterManager.UpdateAll(this.dsShiftReport); 
    } 


    // shiftDeadTime 
    private void toolStripButton8_Click(object sender, EventArgs e) 
    { 
     this.Validate(); 
     this.shiftsBindingSource1.EndEdit(); 
     this.shiftDeadTimeBindingSource.EndEdit(); 

     this.tableAdapterManager.UpdateAll(this.dsShiftReport); 
    } 

そして最後に、datasource.designer.csに - 2つの関係/制約が同一の設定のように見えます。

fkc = new global::System.Data.ForeignKeyConstraint("FK_BargeDetail_Shifts", new global::System.Data.DataColumn[] { 
        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] { 
        this.tableBargeDetail.ShiftIDColumn}); 
    this.tableBargeDetail.Constraints.Add(fkc); 
    fkc.AcceptRejectRule = global::System.Data.AcceptRejectRule.None; 
    fkc.DeleteRule = global::System.Data.Rule.Cascade; 
    fkc.UpdateRule = global::System.Data.Rule.Cascade; 

    fkc = new global::System.Data.ForeignKeyConstraint("FK_ShiftDeadTime_Shifts", new global::System.Data.DataColumn[] { 
        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] { 
        this.tableShiftDeadTime.ShiftIDColumn}); 
    this.tableShiftDeadTime.Constraints.Add(fkc); 
    fkc.AcceptRejectRule = global::System.Data.AcceptRejectRule.None; 
    fkc.DeleteRule = global::System.Data.Rule.Cascade; 
    fkc.UpdateRule = global::System.Data.Rule.Cascade; 

    this.relationFK_BargeDetail_Shifts = new global::System.Data.DataRelation("FK_BargeDetail_Shifts", new global::System.Data.DataColumn[] { 
        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] { 
        this.tableBargeDetail.ShiftIDColumn}, false); 
    this.Relations.Add(this.relationFK_BargeDetail_Shifts); 

    this.relationFK_ShiftDeadTime_Shifts = new global::System.Data.DataRelation("FK_ShiftDeadTime_Shifts", new global::System.Data.DataColumn[] { 
        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] { 
        this.tableShiftDeadTime.ShiftIDColumn}, false); 
    this.Relations.Add(this.relationFK_ShiftDeadTime_Shifts); 

これは私を夢中にしています!私はこのような状況で行うことをお勧め何

答えて

0

:かどうか確認変更は、少なくともデータセットに反映されている場合は、あなたが知っているように、

this.dsShiftReport.GetChanges(); 

を呼び出すことにより、データセット に登場して変更。

フォーム上に何らかの種類のDataGridViewコントロールがあり、DataGridViewにテーブルをバインドしていると仮定します。私は間違っているかもしれませんが(私はWinFormsとDataSetsをしばらく使っていませんが)、 "保存"ボタンを押す前に "入力"したり、DataGridView内の別の行に移動しようとするとどうなりますか?この場合、データは保存されます。

関連する問題