.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Help with DataSet in C# - simple relations between tables
 

Help with DataSet in C# - simple relations between tables

Hi,

I'm having a rather annoying problem with datasets in C# and visual studio 2008.
The scenario is that I want to get the children of a table.

The database has 2 tables, one named chapters and another one named section. The section table has a field called chapter_id, which I use to determine the parent of the section.

Both tables are inserted into a dataset, and I create the relationship between chapters and section, combining chapter.id with section.chapter_id.

Seams simple enough, so when I try the following, the code never returns any children of the chapterRow


DiscoDBDataSetenTableAdapters.chaptersTableAdapterchap=newDisco.DiscoDBDataSetenTableAdapters.chaptersTableAdapter();
DiscoDBDataSeten.chaptersDataTablechapDataTbl=chap.GetData();
foreach(DiscoDBDataSeten.chaptersRowrowinchapDataTbl){
DiscoDBDataSeten.sectionsRow[]chapter_sections=row.GetsectionsRows();
//sectionRow[]isalwaysempty
}


I’m grateful for any help i can get, been stuck at this way to long now. Also I have confirmed that the data exists and all. Another workaround I tried was to have another tableAdapter for the section and use that one to fetch sections accordingly to their match to chapter.id. But I'd rather not resort to that In the whole program.

I've also got the same problems in one-to-one relations.

Does not the standard generated functions from relations in the dataset work?

Best regards

// Martin

Martin Karlsson

Let me rephrase my question.

I simply want to get the children of a parent table. The dataset that I use have been created through the dataset design view in VS 2008. I'm using sql compact 3.5 as DB. In the dataset design I have 2 tables and a relation between them.

I get one row from the parent table by calling a .GetData().first() on the tableAdapter. So far so good, the DataRow that I get have all its data. The DataRow also have a function generated by the dataset design view to get the children of the row. In this case, chapterRow.getSectionRows()

But every time I call that function I get zero rows back (the needed data exists in the database).

I've looked into this in debug mode, and it seems the chapterRow that I have does not have any child relations defined (looked under chapterRow.table.childrelations). Should not the relations defined in the dataset design view been implemented here? Because what good is an auto generated function to get its children (getSectionRows), if that function relies on data the user must import by defining the relation again in the code?

// Martin

Martin Karlsson

You can use google to search for other answers

Custom Search

More Threads

• AddIn: deployment and installation of host application
• File Copying with StreamReader/Writer
• Make a reference always go to the highest version from gac
• File Copier and Verifier Threads
• using dispose/finalize..
• Multithreading and locking--performance impact
• Adding a handler for AppDomain events from a class instance requires serialization of the calling class?
• How to retrieve a ConfigurationSectionGroup?
• Windows Service using .NET - Unexpected termination of service
• Using reflection to load GAC assemblies