473,480 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading dataset from XML problem

Hi,

(Sorry for duplicate post, finger trouble before I finished...)

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, so that if the webservice is not available,
then the app will continue to run from my saved dataset. If the web service
is not available, then I load the dataset with the ReadXml method.

All appears to work excellent... However, you may have guessed, I have a
problem.

On form load, I load the dataset into a list box datasource. Most of my
application is happy with this. The listbox loads properly and can be used.

BUT...
in one point of the app, I was reading (DataTable)listbox.DataSource (I have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt32(SiteListBox.SelectedValue.ToString ()));

then trying to read the DR by...

int SiteCount = Convert.ToInt32(DR[0]["SiteCount"].ToString());

This works almost as expected, but some rows in the dataset (Only when
offline and when the dataset is loaded from the XML) are not being read.

It is odd, but the first 23 rows read OK, the 24, 25 and 26 give an error,
then some later rows work and some others don't.

While in debug command window, (app is Offline)

DR[0]["SiteCount"] <-- THIS ONE WORKS
"4"
DR[0]["SiteCount"] <-- THIS ONE FAILS.
error: 'DR' is not an array or pointer. Indexing is not available

If I run the app while online, and do the same...
DR[0]["SiteCount"]
{4}
System.ValueType: {System.Int32}
m_value: 4
MaxValue: 2147483647
MinValue: -2147483648
DR[0]["SiteCount"]
{16}
System.ValueType: {System.Int32}
m_value: 16
MaxValue: 2147483647
MinValue: -2147483648

I have looked at the XML. An example is...
<Table>
<ID>68</ID>
<SiteName>BradfordFOCUS.Com</SiteName>
<TownName>Bradford</TownName>
<Colour1>#003399</Colour1>
<Colour2>#FFFFFF</Colour2>
<SiteCount>13</SiteCount>
</Table>

I am selecting on the ID field, though the app seems to fail where the ID
number is not in sequential order, though this is not a guaranteed fault as
it can still fail when in sequential order.

Can anyone point me in the right direction?

Thanks.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Feb 19 '07 #1
4 3221
Hi,

"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi,
is happy with this. The listbox loads properly and can be used.
>
BUT...
in one point of the app, I was reading (DataTable)listbox.DataSource (I
have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt32(SiteListBox.SelectedValue.ToString ()));

then trying to read the DR by...

int SiteCount = Convert.ToInt32(DR[0]["SiteCount"].ToString());

This works almost as expected, but some rows in the dataset (Only when
offline and when the dataset is loaded from the XML) are not being read.

It is odd, but the first 23 rows read OK, the 24, 25 and 26 give an error,
then some later rows work and some others don't.
Can you post the exact error? (I assume it's an exception)

It is possible that the select you are doing returns no rows, are you taking
this into consideration?

What about if the listbox has nothing selected?
--
Ignacio Machin
machin AT laceupsolutions com
Feb 19 '07 #2
In the Debug window, the error is...
error: 'DR' is not an array or pointer. Indexing is not available

(I can't get the error from the app at the moment, as I am in the middle of
writing a large method to connect to a web method, so cannot build with the
error in place. I have gotten around the failure by doing a foreach on the
datarow[], which bypasses it, however, there is definately data available.)

There is definately data there. I have opened the XML myself and navigated
to the row.

The method in question is actually in the OnSelectIndex of the listbox, so
can only happen at that point in time.

It is weird that it all works when connected to the dataset from the web
service, but not the dataset from the XML. (The XML data is saved locally
(as a dataset.writexml) as soon as it is received from the webservice, for
use if the webservice is not available.)

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:OR*************@TK2MSFTNGP05.phx.gbl...
Hi,

"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi,
is happy with this. The listbox loads properly and can be used.
>>
BUT...
in one point of the app, I was reading (DataTable)listbox.DataSource (I
have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt32(SiteListBox.SelectedValue.ToStrin g()));

then trying to read the DR by...

int SiteCount = Convert.ToInt32(DR[0]["SiteCount"].ToString());

This works almost as expected, but some rows in the dataset (Only when
offline and when the dataset is loaded from the XML) are not being read.

It is odd, but the first 23 rows read OK, the 24, 25 and 26 give an
error,
then some later rows work and some others don't.

Can you post the exact error? (I assume it's an exception)

It is possible that the select you are doing returns no rows, are you
taking this into consideration?

What about if the listbox has nothing selected?
--
Ignacio Machin
machin AT laceupsolutions com

Feb 19 '07 #3
I guess this is not as simple to fix as I thought...

I am still struggling with this, so any help would be most welcome.

Thinking further into it...

When I am connected to the webservice, the data type is shown when I do the
DR[0]["SiteName"] but not when I read from the XML file that I saved
earlier. If this is likely to be the issue, then how do I save the datatypes
to the XML and reload them when I read it from the XML?

I have been using dataset.WriteXml(filename) and dataset.ReadXml(filename).

Thanks.
--
Best regards,
Dave Colliver.
http://www.MyLocalFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:OO**************@TK2MSFTNGP05.phx.gbl...
In the Debug window, the error is...
error: 'DR' is not an array or pointer. Indexing is not available

(I can't get the error from the app at the moment, as I am in the middle
of writing a large method to connect to a web method, so cannot build with
the error in place. I have gotten around the failure by doing a foreach on
the datarow[], which bypasses it, however, there is definately data
available.)

There is definately data there. I have opened the XML myself and navigated
to the row.

The method in question is actually in the OnSelectIndex of the listbox, so
can only happen at that point in time.

It is weird that it all works when connected to the dataset from the web
service, but not the dataset from the XML. (The XML data is saved locally
(as a dataset.writexml) as soon as it is received from the webservice, for
use if the webservice is not available.)

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Feb 21 '07 #4
Sorted it...

When I read the dataset from the webservice, I am now writing out the schema
as well dataset.WriteXmlSchema, then when I read in the dataset from the
XML, I will read the dataset.ReadXmlSchema prior to ReadXml.

This appears to make it work.

--
Best regards,
Dave Colliver.
http://www.LeicesterFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:ut**************@TK2MSFTNGP02.phx.gbl...
>I guess this is not as simple to fix as I thought...

I am still struggling with this, so any help would be most welcome.

Thinking further into it...

When I am connected to the webservice, the data type is shown when I do
the DR[0]["SiteName"] but not when I read from the XML file that I saved
earlier. If this is likely to be the issue, then how do I save the
datatypes to the XML and reload them when I read it from the XML?

I have been using dataset.WriteXml(filename) and
dataset.ReadXml(filename).

Thanks.
--
Best regards,
Dave Colliver.
http://www.MyLocalFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:OO**************@TK2MSFTNGP05.phx.gbl...
>In the Debug window, the error is...
error: 'DR' is not an array or pointer. Indexing is not available

(I can't get the error from the app at the moment, as I am in the middle
of writing a large method to connect to a web method, so cannot build
with the error in place. I have gotten around the failure by doing a
foreach on the datarow[], which bypasses it, however, there is definately
data available.)

There is definately data there. I have opened the XML myself and
navigated to the row.

The method in question is actually in the OnSelectIndex of the listbox,
so can only happen at that point in time.

It is weird that it all works when connected to the dataset from the web
service, but not the dataset from the XML. (The XML data is saved locally
(as a dataset.writexml) as soon as it is received from the webservice,
for use if the webservice is not available.)

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

Feb 21 '07 #5

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

Similar topics

2
2252
by: Chuck Ritzke | last post by:
Hi all, I am getting an intermittant error after uploading a project from my development machine. I click on a link which opens an aspx page that, upon page load, reads a very small amount of...
5
8924
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
1
2166
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...
6
1393
by: Camper Joe | last post by:
Here's my code: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim db As New SqlConnection Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &...
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...
5
5048
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
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,...
8
3740
by: T Driver | last post by:
Anyone have any idea how I can do the following? I have a connection to an XML file on a site I do not control, getting a string representation of the xml data that I can then feed to my...
1
4668
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
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
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
6873
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...
0
5321
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
4767
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
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
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...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.