Solved

Relationships between two xml

Posted on 2006-10-27
4
248 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now