Solved

Relationships between two xml

Posted on 2006-10-27
4
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

690 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