none
Get ID from Parenttable

    Question

  • Hello dear community,

    i have 2 tables with a relationship. Now when i add a new row to the Articlebindingsource i want the ID of the Ordertable to be inserted into the OrderID Column of the Articeltable. Is there an easy way to solve this or do i have to make a sql que and ask for the ID of the Parenttable and paste it?





    • Edited by murado1 Sunday, April 16, 2017 11:55 AM
    Saturday, April 15, 2017 8:49 PM

Answers

  • There is GetParentRow and GetChildRow methods to obtain information in either direction. Both work off the relationship setup under the BindingSources at the DataSet level.

    See MSDN documentation.

    Here is an example to work with

    var parentId = ((DataRowView)Articlebindingsource.Current).Row.GetParentRow("YourRelationshipNameGoesHere").Field<int>("id");


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Sunday, April 16, 2017 11:25 AM
    Moderator