Solved

Relationships between two xml

Posted on 2006-10-27
4
254 Views
Last Modified: 2010-07-27
I'm creating a PDA app.
I'm using xml files as tables of a database.

When I select the CompanyName from a comboBox
I want the options in table2 that are equals to that CompanyName (using a ID to map)
to display in a second comboBox.

Can anyone help me because I have no clue how to do this.
This is how I get the xml in the comboBox :

//Set file names and create file streams
xmlFileName = "\\My Documents\\Company.xml";
xsdFileName = "\\My Documents\\Company.xsd";
FileStream FsXML = new FileStream(xmlFileName,FileMode.Open);
FileStream FsXSD = new FileStream(xsdFileName,FileMode.Open);
      
      XmlTextReader xtrXML = null;
      xtrXML = new XmlTextReader(FsXML);
      companyDS.ReadXml(xtrXML);
      xtrXML.Close();
      FsXML.Close();
      // Get a DataTable to conveniently use for binding.
      dt = companyDS.Tables["record"];
      //Bind the list box to state abreviations.
      comboBox1.DataSource = dt;
      comboBox1.DisplayMember = "CompanyName";
0
Comment
Question by:argus42
  • 3
4 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17818432
can u post the xml file what does it contain
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17818440
and what is in ur dataset
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17818454
if u have the second table in ur dataset then u dont have to establish any relation btw the xml

all u have to do is apply row filter to uur second table and apply that tables default view to the combobox as u have done
0
 
LVL 12

Accepted Solution

by:
sumix earned 500 total points
ID: 17824808

If you have the two tables in the dataset, i'll call them Companies and Employees for example, you can set a relation like this:
 
 CompaniesDS.Relations.Add("MyRelation",
    CompaniesDS.Tables["Companies"].Columns["CompanyID"],       // column in parent table
    CompaniesDS.Tables["Employees"].Columns["CompanyID"]);      // column in child tablle

than, you can accomplish what you want very easy, by setting the DataSource and DisplayMember properties of the two combobxes this way:
comboBox1.DataSource = CompaniesDS.Tables["Companies"];
comboBox1.DisplayMember = "CompanyName";
comboBox2.DataSource = CompaniesDS.Tables["Companies"];  // the same data source - parent table !!!
comboBox2.DisplayMember = "MyRelation.EmployeeName";   // use here the relation name and the field in the child table !!!

btw, is there any reason for not reading the xml file in a simpler way, like:
    DataSet CompaniesDS = new DataSet();
    CompaniesDS.ReadXml("Company.xml");  ?

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question