none
Adding column to dataset via designer causes "cannot find the parent relation" exception RRS feed

  • Question

  • I have added two columns to a rather complex dataset via the designer.  When I execute an add record against this dataset the app throws an exception with the message "Cannot find the parent relation".  I have been all thru the code and the relation is defined.  I have deleted the relation and readded it with the same exception being thrown.  I have done many searches and found that this is an existing issue that was supposedly resolved.  However, I have also found additional posting on connect.microsoft... that people are still seeing this issue in current VS releases including VS 2008 SP1, which is what I am running.
    Monday, November 16, 2009 11:19 PM

All replies

  • Hi bobtesch,

     

    Could you provide the feedback on connect.microsoft you mentioned?
    If it is this feedback, it doesn’t have the same scenario as yours.

    It throws the exception when call GetChanges, this issue is fixed already.

    The sample code is like this,

            static void Main(string[] args)

            {

                DataSet ds = CreateRelationDataSet();

                DataSet ds2 = null;

     

                try

                {

                    ds2 = ds.GetChanges();

                }

                catch (Exception exc)

                {

                    Console.WriteLine(exc.ToString());

                }

     

            }

            public static DataSet CreateRelationDataSet()

            {

                DataSet ds = new DataSet();

                DataTable dt1 = new DataTable();

                DataTable dt2 = new DataTable();

     

                // Crate the relationships

                dt1.Columns.Add(new DataColumn("Pri1"));

                dt1.Columns.Add(new DataColumn("Name"));

                dt2.Columns.Add(new DataColumn("Sec2"));

                dt2.Columns.Add(new DataColumn("Sec2Name"));

     

                ds.Tables.Add(dt1);

                ds.Tables.Add(dt2);

     

                // Create DataRelations

                ds.Relations.Add(new DataRelation("NameRelation", dt1.Columns[0], dt2.Columns[0], false));

     

                dt2.Columns[1].Expression = "Parent.Name";

     

                // Add Some data

                for (int i = 0; i < 5; i += 1)

                {

                    DataRow dr = ds.Tables[0].NewRow();

                    dr[0] = i;

                    dr[1] = "Fred" + i.ToString();

                    ds.Tables[0].Rows.Add(dr);

     

                    dr = ds.Tables[1].NewRow();

                    dr[0] = i;

                    ds.Tables[1].Rows.Add(dr);

                }

                return ds;

            }

     

        }

    Do you mean you have one datetable with relationship to other table and youadd two column to it?

    Do the two columns exist in DB?

    Could you provide the code sample you are working with?

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, November 19, 2009 5:49 AM
  • I have a datatable in a dataset designer named Ticket.  In the same dataset is another dt named Assignment.  Connecting the two is a relation that links on the ticketid field.  I need to add a column to the "ticket" dt named "TicketCreated".  After this is done and the application adds a new row to the "tickets" table that the ticket dt is based on and open the form to finish populating the data (that has a control on it that gets the assignment history, which the new ticket does not have any) and the app throws an exception stating "cannot find the parent relation Ticket_Assignment".  The only thing that was changed was the adding of the column.  However, when you look at the previous version of the files associated with the dataset designer and the one after the addition of the column, the new file is totally rearranged, etc.  Why would a simple change like this cause so much havoc?  FYI, from reading the Connect.microsoft thread you pointed out, if the problem is really fixed, you need to spread the word better or provide access to the patch.
    Thursday, November 19, 2009 9:18 PM
  • Also I have this marked to notify me of replies and I have not gotten one.  I checked with our spam people and they did not catch anything, so I think there is a problem with the notifications.
    Thursday, November 19, 2009 9:23 PM
  • Hi Bob,

    Are you using strong typed dataset?
    If it is that, the added column will not save to the database. Since the dataset schema file is pregenerated accroding to the DB. Could you provide the sample code you are working with?

    The feedback fixed means that the scenario will not throw the exception, not the exception will never throw. There are several scenario can cause this exception.
    The code block I post previously is the sample that the customer provided. And it runs well in VS2008.


    Best Regards
    Yichun Feng
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, November 23, 2009 9:07 AM
  • I have narrowed it down to the following section of code in an .xsd file for the dataset in question.  All of the msprop values are be flagged with warnings for "attribute not declared".  I think if I can get this resolved, the remainder of the issues surrounding this will fall into place.  

     

     

     

     

      <xs:annotation>
        <xs:appinfo>
          <msdata:Relationship msdata:RelationName="Workflow_WorkflowContacts" msdata:parent="Workflow" msdata:child="WorkflowContacts" msdata:parentKey="WorkflowID" msdata:childKey="WorkflowID" msprop:Generator_UserRelationName="Workflow_WorkflowContacts" msprop:Generator_RelationVarName="relationWorkflow_WorkflowContacts" msprop:Generator_UserChildTable="WorkflowContacts" msprop:Generator_UserParentTable="Workflow" msprop:Generator_ParentPropName="WorkflowRow" msprop:Generator_ChildPropName="GetWorkflowContactsRows" />
          <msdata:Relationship msdata:RelationName="Groups_GroupMembers" msdata:parent="Groups" msdata:child="GroupMembers" msdata:parentKey="GroupID" msdata:childKey="GroupID" msprop:Generator_UserRelationName="Groups_GroupMembers" msprop:Generator_RelationVarName="relationGroups_GroupMembers" msprop:Generator_UserChildTable="GroupMembers" msprop:Generator_UserParentTable="Groups" msprop:Generator_ParentPropName="GroupsRow" msprop:Generator_ChildPropName="GetGroupMembersRows" />
          <msdata:Relationship msdata:RelationName="Ticket_Assignment" msdata:parent="Ticket" msdata:child="Assignment" msdata:parentKey="TicketID" msdata:childKey="TicketID" msprop:Generator_UserRelationName="Ticket_Assignment" msprop:Generator_RelationVarName="relationTicket_Assignment" msprop:Generator_UserChildTable="Assignment" msprop:Generator_UserParentTable="Ticket" msprop:Generator_ParentPropName="TicketRow" msprop:Generator_ChildPropName="GetAssignmentRows" />
          <msdata:Relationship msdata:RelationName="KeywordTicket_Keyword" msdata:parent="KeywordTicket" msdata:child="Keyword" msdata:parentKey="KeywordID" msdata:childKey="KeywordID" msprop:Generator_UserRelationName="KeywordTicket_Keyword" msprop:Generator_RelationVarName="relationKeywordTicket_Keyword" msprop:Generator_UserChildTable="Keyword" msprop:Generator_UserParentTable="KeywordTicket" msprop:Generator_ParentPropName="KeywordTicketRow" msprop:Generator_ChildPropName="GetKeywordRows" />
        </xs:appinfo>
      </xs:annotation>
    

     

    Monday, November 23, 2009 9:06 PM