Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 86279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:13:16+00:00 2026-05-10T22:13:16+00:00

I created two tables: Publisher PK, PublisherId, int, not null, indentity +1 PublisherName, varchar(50),

  • 0

I created two tables:

Publisher

  • PK, PublisherId, int, not null, indentity +1
  • PublisherName, varchar(50), not null

Product

  • PK, ProductId, int, not null, identity +1
  • ProductName, varchar(50), not null
  • PublisherId, int, not null

Then I created a foreign key constraint FK__Product__Publisher between those tables connecting the PublisherId’s.

This way I want to support Products that have one Publisher each while each Publisher can have multiple Products. It’s as simple as that.

Now I created a console project in C#, added a typed dataset and two TableAdapter. One pointing to Publisher one to Product. The DataSet-Designer automatically adds the relation based on what it gets from SQL Server.

It also automatically generates properties which should allow me to access the publisher from a selected Product and all products from a selected publisher.

This is my test code:

ProductTableAdapter adapter = new ProductTableAdapter();  foreach (ProductRow product in adapter.GetData()) {     Console.WriteLine(product.PublisherRow.PublisherName); } 

However, this does not work. With the generated code, the property PublisherRow looks like this:

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public LanguageRow PublisherRow {     get {         return ((PublisherRow)(this.GetParentRow(this.Table.ParentRelations['FK_Product_Publisher'])));     }     set {         this.SetParentRow(value, this.Table.ParentRelations['FK_Product_Publisher']);     } } 

this.Table.ParentRelations does not contain the relation. It is null and accessing it results in a NullReferenceException.

What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:13:17+00:00Added an answer on May 10, 2026 at 10:13 pm

    It seems a little weird answering my own post. It’s a little like talking to myself. However, I sort of found a solution and since this problem seems to be pretty common, I post it here.

    Simply using the TableAdapters to get the data will not retrieve the proper relations from the database. The initialization of the relationships takes place within the dataset class (namely the InitClass method which is called from the datasets’ c’tor):

    public DbDataSet() {     this.BeginInit();     this.InitClass();     ...     this.EndInit(); } 

    The corresponding generated InitClass method looks like this:

    private void InitClass() {     ...     this.relationFK_Product_Publisher= new global::System.Data.DataRelation('FK_Product_Publisher', new global::System.Data.DataColumn[] { this.tableProduct.PublisherIdColumn}, new global::System.Data.DataColumn[] { this.tablePublisher.PublisherIdColumn}, false);     this.Relations.Add(this.relationFK_Product_Publisher); } 

    This is why you need to instantiate the dataset class itself and use the fill method to populate your table classes like this:

    DbDataSet ds = new DbDataSet();      ProductTableAdapter productAdapter = new ProductTableAdapter();             productAdapter.Fill(ds.Product);  PublisherTableAdapter publisherAdapter = new PublisherTableAdapter(); publisherAdapter.Fill(ds.Publisher);  foreach (ProductRow product in ds.Product) {                     Console.WriteLine(product.PublisherRow.PublisherName); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1

Related Questions

No related questions found

  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer In order to fire the HttpModule you have to have… May 11, 2026 at 8:54 am
  • added an answer try this: def initialize(): global VAR print('Content-type: text/html\n\n') print(VAR) VAR… May 11, 2026 at 8:54 am
  • added an answer Let me google that for you :) EDIT : Add… May 11, 2026 at 8:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.