473,467 Members | 2,010 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 3218
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
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
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
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
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
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
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
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
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
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.