Master/Detail BindingSource foreign key not found error

    General discussion

  • Hi,

    I followed the instructions on msdn for the master/detail example where the detail BindingSource is chained to the master BindingSource. But when i integrate the same steps into our current project it only throws the following exception:

    System.ArgumentException: DataMember property 'ActionRoles' cannot be found on the DataSource. ...

    The DataSet contains (was created with the designer):

    Table: tblAction
        Col: ID
        Col: Name
        Col: Description
    Table: tblRoleAction
        Col: RoleID
        Col: ActionID
        Col: ID

    The designer inserted the relation "ActionRoles" between the two Tables. The relation points with the key symbol to the tblAction table. So its a one-to-many relation and it is already available in the DataSet.

    The code where the exception occurs is:

    m_Binding = new BindingSource();
    m_Binding.DataSource = AuthData.Instance.DataSet;
    m_Binding.DataMember = AuthData.Instance.DataSet.tblRoleAction.TableName;
    m_DetailBinding = new BindingSource();
    m_DetailBinding.DataSource = m_Binding;
    m_DetailBinding.DataMember = "ActionRoles"; // Exception here

    The Tables in the DataSet get filled before any of the code above is executed. Also the data in the DataSet is displayed by a GridView beforehand without any errors.

    I can't find anything wrong about it?!?
    • Changed type Bruce.Zhou Friday, April 24, 2009 10:37 AM Not followed up in time
    Sunday, April 19, 2009 1:33 PM

All replies

  • Check your data.  I think you have a master record with no details
    Sunday, April 19, 2009 1:42 PM
  • The "tblRoleAction.ActionID" (FK) points to "tblAction.ID" (PK). This is represented by the "ActionRoles" DataRelation in the DataSet.

    If the "tblAction" is the Master it should not matter if there are entries in the "tblAction" that are not referenced by "tblRoleAction".

    If the "tblRoleAction" is the Master it is not possible to reference a not existing entry in "tblAction" because of the settings in the database (FK constraints).

    "tblAction.ID" contains values 1 to 16

    "tblRoleAction.ActionID" contains mixed values between 1 and 16.

    How should i proceed?
    Sunday, April 19, 2009 2:01 PM
  • Hi Anton81,

    The error indicates ActionRoles can't be found in the underlying datasource. You can place a breakpoint under the following statement:
    m_Binding.DataMember = AuthData.Instance.DataSet.tblRoleAction.TableName;
    and add a watch to observe the DataSource of the m_Binding object, check if there is ActionRoles.

    Also, try to create datarelation in the dataset by writing code instead of making it in the designer in case we made mistake there. The code will not be that complex, as you can refer to this document .

    Please let me know if all the suggestions can't work.

    Best regards,
    Bruce Zhou
    Please mark the replies as answers if they help and unmark if they don't.
    Tuesday, April 21, 2009 12:50 PM
  • We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Please mark the replies as answers if they help and unmark if they don't.
    Friday, April 24, 2009 10:37 AM