Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Relationships between two xml

Posted on 2006-10-27
4
Medium Priority
?
259 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 1500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

963 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