none
A TableRow referenced trought a DataRelation always returns null RRS feed

  • Question

  • Hello,

    Using the DataSet designer in Visual Studio 2010, I've added some tables from a MySql DB. VS10 automatically picks up and adds the relations between the tables, e.g., the relation "FK_organisatie_adres" between the tables "Organisatie" and "Adres": VS DataSet designer with 2 table and relationship

    In the C# code, a property was automatically generated that "resolves" that relationship: a row of Organisatie has a property .adresRow (I assume through the detected relation "FK_organisatie_adres") VS auto generated property to get the related adresRow

    Problem: when running the code, the "theAddress" (hence the .adresRow property) is ALWAYS null!

    Also the "theOrganisationRow.GetChildRows("FK_organisatie_adres")" always return null. and the "organisationDT.ChildRelations" is empty.

    What am I doing wrong? What do I need to do extra before I can use the automatically generate .adresRow property?

    Friday, March 4, 2011 7:16 PM

Answers

  •  

    Hi Robbie,

    Welcome to MSDN forums.

    You are right VS create the relationship according to your DB, There is some things wrong within your code.

    Firstly, the relations in create in Dataset, so you should use Dataset to create your datatable, like this way:

          DataSet1 ds = new DataSet1();
          DataSet1TableAdapters.EmployeeTableAdapter eAdapter = new DataSet1TableAdapters.EmployeeTableAdapter();
          DataSet1.EmployeeDataTable etable =ds.Employee;//here is important
          eAdapter.Fill(etable);
          
          DataSet1TableAdapters.VacationTableAdapter vAdapter = new DataSet1TableAdapters.VacationTableAdapter();
          DataSet1.VacationDataTable vd = ds.Vacation;///
          vAdapter.Fill(vd);
          var te = vd[0].EmployeeRow;
    

    You can refer this link: http://kjellsj.blogspot.com/2005/10/tableadapter-with-multiple-related.html

     

    Note that the relations are added to the .Relations collection of the DataSet, not as .ChildRelations of the "parent" DataTable. You must use the .Fill() method of each TableAdapter to populate all the DataTables and their DataRelations at run-time. Note that the .GetData() method returns a single DataTable without populating any relations.

    So you couldn't use getdata() method.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 7, 2011 5:36 AM
    Moderator

All replies

  •  

    Hi Robbie,

    Welcome to MSDN forums.

    You are right VS create the relationship according to your DB, There is some things wrong within your code.

    Firstly, the relations in create in Dataset, so you should use Dataset to create your datatable, like this way:

          DataSet1 ds = new DataSet1();
          DataSet1TableAdapters.EmployeeTableAdapter eAdapter = new DataSet1TableAdapters.EmployeeTableAdapter();
          DataSet1.EmployeeDataTable etable =ds.Employee;//here is important
          eAdapter.Fill(etable);
          
          DataSet1TableAdapters.VacationTableAdapter vAdapter = new DataSet1TableAdapters.VacationTableAdapter();
          DataSet1.VacationDataTable vd = ds.Vacation;///
          vAdapter.Fill(vd);
          var te = vd[0].EmployeeRow;
    

    You can refer this link: http://kjellsj.blogspot.com/2005/10/tableadapter-with-multiple-related.html

     

    Note that the relations are added to the .Relations collection of the DataSet, not as .ChildRelations of the "parent" DataTable. You must use the .Fill() method of each TableAdapter to populate all the DataTables and their DataRelations at run-time. Note that the .GetData() method returns a single DataTable without populating any relations.

    So you couldn't use getdata() method.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 7, 2011 5:36 AM
    Moderator
  • Hi Robbie,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 10, 2011 3:12 AM
    Moderator
  • Sorry for the late reply, I was fighting with my code :) but I finally managed thanks to your reply! It works!

    Tuesday, March 15, 2011 7:36 AM