Solved

Relationships between two xml

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

18 Experts available now in Live!

Get 1:1 Help Now