473,486 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading a dataset into XML

I have a table in my SQL Server that I am loading into a datatable. I am
then saving the dataset that this table is a member of (it's the only
table in the dataset) to an XML file so that I can use it offline in
another part of my program. The code I use for this is:

ds.WriteXML("c:\clients.xml") 'DS is my dataset object

This generates an XML file like the following (the entire XML file is
included in this post at the end of the message)

<?xml version="1.0" standalone="yes"?>

<ClientData>

<Clients>

<c_recordid>1</c_recordid>

<c_name>NOL</c_name>

</Clients>

<Clients>

<c_recordid>2</c_recordid>

<c_name>TCG</c_name>

</Clients>

..more clients.

</ClientData>

In another part of my program, which is designed to use when you're
offline and can't connect to the SQL server, I want to reload this
information back into a datatable. I do so using the following code:

ds = New DataSet("ClientData")

ds.ReadXml("c:\clients.xml")

dt = ds.Tables("Clients")

Next, I try to refer to a specific row in the Clients data table in the
following manner:

Dim rows as datarow() = dt.select("c_recordid=" + clientid.tostring)
'ClientID is an integer being passed to the subroutine

Try

Dim row as datarow = rows(0)

Catch ex as Exception

Msgbox ex.tostring

End Try

Because c_recordid is the unique key for the table, I know that only one
row will be returned - hence I can logically refer to row(0). However,
when I call the subroutine setting the ClientID variable to 2,3.10, or
11, I get the following exception when referring trying to access
rows(0):

System.IndexOutOfRangeException: Index was outside the bounds of the
array.

This does not happen when I set ClientID = 1,4,5,6,7,8, or 9. I know all
of these are valid because I've looked at the XML file in it's entirety.
I've checked for strange characters that might be messing it up and
haven't found anything - all in all, I thought it would be an easy
process, but the only thing that is consistent is the ClientID's I can't
access.
Can anyone direct me to what I'm doing wrong, or what might be causing
this thing to blow up? I'd appreciate any help. One last thing. I HAVE
written a little subroutine to loop through each row in the datatable.

Dim r as datarow

For each r in dt.rows

Msgbox r(0) 'Msgbox's the clientid column (1-11)

Next r

This works fine. I see all 11 clients when I loop through them, but
cannot use the .select method to consistently get a particular one.

Thanks,

Chet

Here is the XML file in it's entirety:

<?xml version="1.0" standalone="yes"?>

<ClientData>

<Clients>

<c_recordid>1</c_recordid>

<c_name>NOL</c_name>

</Clients>

<Clients>

<c_recordid>2</c_recordid>

<c_name>TCG</c_name>

</Clients>

<Clients>

<c_recordid>3</c_recordid>

<c_name>CHN</c_name>

</Clients>

<Clients>

<c_recordid>4</c_recordid>

<c_name>CNT</c_name>

</Clients>

<Clients>

<c_recordid>5</c_recordid>

<c_name>CityNet</c_name>

</Clients>

<Clients>

<c_recordid>6</c_recordid>

<c_name>IFN</c_name>

</Clients>

<Clients>

<c_recordid>7</c_recordid>

<c_name>IU</c_name>

</Clients>

<Clients>

<c_recordid>8</c_recordid>

<c_name>Lilly</c_name>

</Clients>

<Clients>

<c_recordid>9</c_recordid>

<c_name>Plainfield</c_name>

</Clients>

<Clients>

<c_recordid>10</c_recordid>

<c_name>St. Vincent</c_name>

</Clients>

<Clients>

<c_recordid>11</c_recordid>

<c_name>IFW</c_name>

</Clients>

</ClientData>


Nov 12 '05 #1
3 1245
I found a posting that said I should try

Ds=ds.copy()

Before doing anything with my data. I tried that and didn't find any
difference. The code to read XML is now:

Ds=new dataset("ClientData") 'Also tried just "ds=new dataset"
Ds=readxml("C:\clients.xml")
Ds=ds.copy()
Dt=ds.tables("Clients")

Nov 12 '05 #2
Chet,

Did you try it already with

ds.WriteXML("c:\clients.xml",XmlWriteMode.WriteSch ema )

or diffgram when you want it with all made changes not accepted.

I hope this helps?

Cor

Nov 12 '05 #3
Well that was TOO easy! THANK YOU, I should have wrote this post 5 hours
ago. I will have to go see what that did different to my XML file.

Again, THANK YOU!

Chet

"Cor Ligthert" <no************@planet.nl> wrote in message
news:no************@planet.nl:
Chet,

Did you try it already with

ds.WriteXML("c:\clients.xml",XmlWriteMode.WriteSch ema )

or diffgram when you want it with all made changes not accepted.

I hope this helps?

Cor


Nov 12 '05 #4

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

Similar topics

1
2768
by: David D. McCrory | last post by:
I have the following that returns an array of a struct and I want to load it into a DataSet on the consumer side.....Can someone provide me with an example of how to use the DataSet.ReadXml()...
0
1104
by: Earl Teigrob | last post by:
I would like to be able to validate an XML file before it is (or as it is being) read into a DataSet. I have a class that dynamically creates a DataSet with typed columns based on another...
5
1310
by: WebBuilder451 | last post by:
is there ant place where i can learn the basics of reading an rss feed and enumerating through the values? just want to start at the bottom, no frills. thanks -- thanks (as always) some day...
1
2167
by: hzgt9b | last post by:
(FYI, using VB .NET 2003) Can someone help me with this... I'm trying to read in an XML file... it appears to work in that the DataSet ReadXML method dose not fail and then I am able to access the...
4
12763
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
3
8006
by: Brad | last post by:
I'm having a problem reading data from an Excel file into a dataset. Can anybody give me an idea of what's happening? I've included the problematic source and the error message to the end of this...
0
361
by: David | last post by:
Hi, using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data, I write the dataset out to the local disk using DataSet.WriteXml,...
5
5219
by: Hetal | last post by:
Hi there.. I am a VB6 developer so kinda trying to figure how to work with VB.NET. I have a scenario where i have a DataSet bound to a combo box, and i would like to read a row from the DataSet...
2
1918
by: pkenderdine | last post by:
Can someone please advise the best approach for reading in many 5000+ xml files from disk into a data set. Here is the code so far. On my computer (may not be best spec) is takes about 3 minutes to...
1
4669
by: sachinkale123 | last post by:
Hi, I am reading excel file and reading values from that I am using provider As : "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Filename + ";Extended Properties=\"Excel 8.0;Hdr=No;IMEX=1\"";...
0
6967
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
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
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...
1
6846
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
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.