473,796 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ 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.WriteXm l, 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)list box.DataSource (I have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt32 (SiteListBox.Se lectedValue.ToS tring()));

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.ValueTyp e: {System.Int32}
m_value: 4
MaxValue: 2147483647
MinValue: -2147483648
DR[0]["SiteCount"]
{16}
System.ValueTyp e: {System.Int32}
m_value: 16
MaxValue: 2147483647
MinValue: -2147483648

I have looked at the XML. An example is...
<Table>
<ID>68</ID>
<SiteName>Bradf ordFOCUS.Com</SiteName>
<TownName>Bradf ord</TownName>
<Colour1>#00339 9</Colour1>
<Colour2>#FFFFF F</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 3257
Hi,

"David" <da************ *****@revilloc. REMOVETHIS.comw rote in message
news:%2******** ********@TK2MSF TNGP02.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)list box.DataSource (I
have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt32 (SiteListBox.Se lectedValue.ToS tring()));

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.writexm l) 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******** *****@TK2MSFTNG P05.phx.gbl...
Hi,

"David" <da************ *****@revilloc. REMOVETHIS.comw rote in message
news:%2******** ********@TK2MSF TNGP02.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)list box.DataSource (I
have
changed it now, but it made no difference) then

DataRow[] DR = DT.Select("ID = " +
Convert.ToInt3 2(SiteListBox.S electedValue.To String()));

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.WriteXm l(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.comw rote in message
news:OO******** ******@TK2MSFTN GP05.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.writexm l) 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.WriteXm lSchema, then when I read in the dataset from the
XML, I will read the dataset.ReadXml Schema 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.comw rote in message
news:ut******** ******@TK2MSFTN GP02.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.WriteXm l(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.comw rote in message
news:OO******** ******@TK2MSFTN GP05.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.writexm l) 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
2288
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 data from an MS Access database, using ODBC and a stored query. There is no problem on my development machine. On the production server though, I get the intermittant error shown below. If I click back and forth between the problem page and the...
5
8958
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 headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
1
2186
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 table names that are in the XML file, but I'm not able to access the rows. Here's the code that I've got - it assumes that the fileName passed in already exists: Public Sub GetInput(ByVal fileName As String) dsFileCopy = New...
6
1412
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 = '" & txtUsername.Text & "'" Dim ds1 As DataSet = New DataSet() db.ConnectionString = "Data Source=.\SQLExpress;Integrated
4
12808
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
5
5089
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 have it store info it gets from when the programs check in into a DataSet (XML file). Problem is, that file now has to be used by other programs to find out version information (the file is ALWAYS less that 1K.) The record itself is only five fields...
3
8029
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 message. TIA Brad Here's a snippet of my source code:
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, 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.
8
3757
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 XmlDataSource object (CurrentXMLData): Stream newStream = myWebClient.OpenRead(myStringWebResource); TextReader newReader = new StreamReader(newStream); string newData = newReader.ReadToEnd(); CurrentXMLData.Data = newData;
1
4702
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\""; Column Name 'Sol 1' and 'Sol 2' is missing even though it is reading the readings. Just not able to read column names. I am not sure about what is exact problem. so please help me in solving this. Thanx in advance.
0
9679
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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 we have to send another system

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.