XML relationship

  • Thread starter Thread starter Leszek
  • Start date Start date
L

Leszek

Hello,

I have two XML files: customers.xml and orders.xml. They are related through
"customerID" field with one-to-many relationship (one customer --> many
orders).
How to create a DataSet containing both of files and reflecting this
relationship? I need this DataSet to be bound to a DataGrid then.

Thanks for any suggestions,
Leszek Taratuta
 
Hi Leszek,

We can use DataSet.ReadXml() method to achieve this. Use 2 datasets to get
the 2 tables separately and use DataSet.Merge() method to combine the two
datasets into one. Then you can add the relationship to the combined one
with DataSet.Relations.Add(). Thus a dataset with both two tables and a
relation is done.

For more information about the DataSet method, please refer to the
following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatasetmemberstopic.asp

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I tried this method but I do not know enough about ADO.NET. Could you
provide me any links to examples or code snippets describing how to
accomplish this?
Also DataSet.Merge() does not seem to be appropriate. It merges rows
horizontally (MSDN: "Merges this DataSet with an array of DataRow objects" -
it seems to be a SQL UNION) but I need a kind of SQL JOIN i.e. a vertical
relationship. With SQL Server there is no problem. I could use
DataAdapter.Fill() to add an additional DataTable to the DataSet, but I need
something similar for XML files.

Thanks,
Leszek Taratuta
 
Hi Leszek,

I think you have only check an overload of the Merge method. To see a
complete overload list of DataSet.Merge(), please refer to the following
link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatasetclassmergetopic.asp

I think you can use public void Merge(DataSet); or public void
Merge(DataTable); to achieve this.

The following is an example of how to write a DataSet with some records to
an Xml file.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatasetclassreadxmltopic2.asp

For an overview of ADO .net, please check the following:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconoverviewofadonet.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top