一見すると、この質問は何度も聞かれていることに気づきます-そして私はそれらの多くを読んだり検索したりしたと思います-そして私は見つけたすべての提案をチェックするために非常に一生懸命努力しました-
たぶん私はもう一組の目が必要ですか?
問題はこれです:私はマスターテーブルと2つの詳細テーブルを持っています。それらは私のデータソースでデータベースとまったく同じように定義されており、同じ関係とキー/FKフィールド/タイプがあります。
テーブルにデータを手動で入力でき、クエリ(左結合など)で期待どおりの結果が得られます。また、アプリケーションでレコードを正しく表示できます-正しい親レコードに結合されています。
ただし、これらのテーブル/BindingSourcesの1つだけが正しく機能しています。私は私が見ることを知っているどこでも見ました、そして違いを見ることができませんか?
BargeDetailsテーブルバインディングソースは完全に機能します。ShiftDeadTimeは、データベースへのレコードの保存/挿入を行いません。
確認したところ、bindingsource.count = 1であり、基になるbindingsource.currentに期待値があります。
SQLトレースは、挿入/更新の試みを示していません。
Visual Studio 2010、ADO.NET、.NET 4とWinForms、およびSQL Server 2008を使用しています。データソースは設計されており、最初にデザイナーを使用してコードを作成するのではありません。詳細なバインディングソースを変更して、正しいdatasource / 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);
}
バインディングソースは同じように設定されているようです。
shiftDeadTimeBindingSource
datasource = shiftsBindingSource1
datamember = FK_ShiftDeadTime_Shifts
bargeDetailBindingSource
datasource = shiftsBindingSource1
datamember = FK_BargeDetail_Shifts
dgShiftDeadTime
datasource = shiftDeadTimeBindingSource
クリック/保存イベントでは、正しい/類似のEndEdit()とUpdateAll()があるように見えます。
// 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);
これは私を夢中にさせています!