none
Can i somehow link two DataRows in two DataTables so that changes in cell 1 in Row A will result in changes of cell 1 in row B? RRS feed

  • Question

  • Question as in the title.

    I almost doubt it, but one can hope, no?

    Edit: Nevermind.

    • Changed type s5340409 Monday, May 3, 2010 10:16 PM
    • Moved by SamAgain Tuesday, May 4, 2010 4:07 AM better fit (From:.NET Base Class Library)
    • Moved by VMazurModerator Tuesday, May 4, 2010 10:29 AM (From:ADO.NET Managed Providers)
    • Changed type s5340409 Wednesday, May 5, 2010 7:39 PM Wanted to mark an answer
    Monday, May 3, 2010 3:33 PM

Answers

  • Yes.. Willl work.  It must be 2 different Data Table Instances.

    You have to Create the Data View of the like this.

    Consider DataTable1 is your parent, and DataTable2 is your Child.

    When you create the dataview for datatable2 if any changes in the parent record from DT1 will immediately updated back to the Datatable2 rows.

    for that you have to create the dataview like this.

    Dim DT1DataView, DT2DataView As DataView
    
    DT1DataView = DataSet.Tables("DataTable1")
    
    '' Creating the child view based on the parent table 0th Row. it will make the chages in child dataview
    
    DT2DataView = DT1DataView.Item(0).CreateChildView("<RelationShipName>")
    
    DT1DataView.Item(0).BeginEdit()
    
    DT1DataView.Item(0)("RelationShipColumn") = "ModifySomeValue"
    
    DT1DataView.Item(0).EndEdit()
    
    ''after endedit the value in the relationshipcolumn of dataview2 also gets updated. considered that the dataset is already defined the relation ship. i have posted in the 1st slide.
    
    

     

     


    Best Regards,
    Gopi V

    If you have found this post helpful, please click the Vote as Helpful link (the green triangle and number on the top-left).

    If this post answers your question, click the Mark As Answered link below. It helps others who experience the same issue in future to find the solution.

    • Marked as answer by s5340409 Wednesday, May 5, 2010 7:40 PM
    Wednesday, May 5, 2010 5:05 AM

All replies

  • Hii..

    Yes you can do that by specifying the DataRelation.

    To do that you have to put those tables in the DataSet and need to Add the Relation.

    something like this

    Dim MergeDataSet As DataSet = New DataSet
    MergeDataSet.Tables.Add(DataTable1)
    MergeDataSet.Tables.Add(DataTable2)
    MergeDataSet.Relations.Add("ForeignKeyRelation", DataTable1.Columns("PrimaryKeyColumnName"), DataTable2.Columns("ForeignKeyColumnName"), True)
    MergeDataSet.Refresh();
    

     

     


    Best Regards,
    Gopi V

    If you have found this post helpful, please click the Vote as Helpful link (the green triangle and number on the top-left).

    If this post answers your question, click the Mark As Answered link below. It helps others who experience the same issue in future to find the solution.

    Tuesday, May 4, 2010 11:14 AM
  • Ah, but does that work if B is a copy of A?

    (I want to dislplay part of a DataTable and doing this specific thing with a DataView might be a bit complicated.)

    Tuesday, May 4, 2010 11:28 PM
  • Yes.. Willl work.  It must be 2 different Data Table Instances.

    You have to Create the Data View of the like this.

    Consider DataTable1 is your parent, and DataTable2 is your Child.

    When you create the dataview for datatable2 if any changes in the parent record from DT1 will immediately updated back to the Datatable2 rows.

    for that you have to create the dataview like this.

    Dim DT1DataView, DT2DataView As DataView
    
    DT1DataView = DataSet.Tables("DataTable1")
    
    '' Creating the child view based on the parent table 0th Row. it will make the chages in child dataview
    
    DT2DataView = DT1DataView.Item(0).CreateChildView("<RelationShipName>")
    
    DT1DataView.Item(0).BeginEdit()
    
    DT1DataView.Item(0)("RelationShipColumn") = "ModifySomeValue"
    
    DT1DataView.Item(0).EndEdit()
    
    ''after endedit the value in the relationshipcolumn of dataview2 also gets updated. considered that the dataset is already defined the relation ship. i have posted in the 1st slide.
    
    

     

     


    Best Regards,
    Gopi V

    If you have found this post helpful, please click the Vote as Helpful link (the green triangle and number on the top-left).

    If this post answers your question, click the Mark As Answered link below. It helps others who experience the same issue in future to find the solution.

    • Marked as answer by s5340409 Wednesday, May 5, 2010 7:40 PM
    Wednesday, May 5, 2010 5:05 AM
  • Thanks, i'll try that.
    Wednesday, May 5, 2010 7:39 PM