473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Manipulating XML data - using a DataSet

Part of an application I'm working on needs to manipulate some XML data (in
an XML file), by reading the data into a DataSet using the MyDataSet.ReadXML
method, and then using MyDataSet.WriteXML to update the XML file itself.
However, now I want to take advantage of the Primary Key functionality of
the DataSet object, so I can easier find rows (in a DataTable in the
DataSet), and also easier remove rows, based on a unique key.
Unfortunately, I'm not sure how that will impact how the XML looks (and I
cannot change the format of that file - it's already used by other
applications).
Here's a snippet of the XML I'm using:

<?xml version="1.0" ?>
<Cache>
<FileCache>
<FileName>Book1.xls</FileName>
<FilePath>C:\Windows\Temp</FilePath>
<OID>3838.64847.26094.60105</OID>
<DateTime>4/5/2005 9:50:45 AM</DateTime>
</FileCache>
<FileCache>
<FileName>Book2.xls</FileName>
<FilePath>C:\Windows\Temp</FilePath>
<OID>3838.64847.18503.25804</OID>
<DateTime>4/5/2005 9:50:56 AM</DateTime>
</FileCache>
</Cache>
The field I need to use as primary key (should be unique) is the OID field.

As you can see, reading that data into a Dataset gives me a DataTable called
Cache, with rows called FileCache (where OID is the third column in those
rows).
How do I tell it to use that column as the primary key, even after I've
loaded it via the LoadXML method, and then how do I do the SaveXML without
adding anything else to the XML layout than what you see above?
Thanks!
Nov 21 '05 #1
1 1760
Never mind everybody... Managed to find the solution myself... :)

If anyone else is having this issue, here's my solution.

After the ReadXML, I added the following line:

MyDataSet.Tables("Cache").PrimaryKey = New DataColumn()
{_MyDataSet.Tables("Cache").Columns("OID")}

"Scott M. Lyon" <sc******************@rapistan.BLUE.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
Part of an application I'm working on needs to manipulate some XML data
(in an XML file), by reading the data into a DataSet using the
MyDataSet.ReadXML method, and then using MyDataSet.WriteXML to update the
XML file itself.
However, now I want to take advantage of the Primary Key functionality of
the DataSet object, so I can easier find rows (in a DataTable in the
DataSet), and also easier remove rows, based on a unique key.
Unfortunately, I'm not sure how that will impact how the XML looks (and I
cannot change the format of that file - it's already used by other
applications).
Here's a snippet of the XML I'm using:

<?xml version="1.0" ?>
<Cache>
<FileCache>
<FileName>Book1.xls</FileName>
<FilePath>C:\Windows\Temp</FilePath>
<OID>3838.64847.26094.60105</OID>
<DateTime>4/5/2005 9:50:45 AM</DateTime>
</FileCache>
<FileCache>
<FileName>Book2.xls</FileName>
<FilePath>C:\Windows\Temp</FilePath>
<OID>3838.64847.18503.25804</OID>
<DateTime>4/5/2005 9:50:56 AM</DateTime>
</FileCache>
</Cache>
The field I need to use as primary key (should be unique) is the OID
field.

As you can see, reading that data into a Dataset gives me a DataTable
called Cache, with rows called FileCache (where OID is the third column in
those rows).
How do I tell it to use that column as the primary key, even after I've
loaded it via the LoadXML method, and then how do I do the SaveXML without
adding anything else to the XML layout than what you see above?
Thanks!

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
2
by: mark | last post by:
Hi, I have a dataset, DataSetTemp which gets filled by the DataAdapter when querying a SQL Server database. Only one table is populated in the data set. I have another dataset, DataSetResults,...
3
by: ASzasz | last post by:
I am new to VB .NET: I can configure a SQL adapter and access data via the datagrid. But how do you access and manipulate data if you do not require the data to show up on a form. I simply want to...
2
by: Daniel Kaseman | last post by:
What's the best way to manipulate a Microsoft Access Database from VB .Net? I have gotten as far as making and configuring a OleDbAdapter, connection, and Dataset, which is bound to a data grid. ...
1
by: Jean Christophe Avard | last post by:
Hi! I am designing an application, and I need some pointers. I have a database that has 5 tables: a table "Items" and 4 other table that has relationship to "Item". I have to retreive all the...
2
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: ...
0
by: Arturo | last post by:
I have constructed a Dataset using visual studio, where tables from my database were dragged and drop into the dataset design page. I wrote code to read data from the database by declaring and...
5
by: Anil Gupte | last post by:
How can I manipulate Datasets, such as getting a specific row based on a key column value. Of course, I could loop through all the rows in the entire dataset each time I needed something, but is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.