473,387 Members | 1,791 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,387 software developers and data experts.

loading xml into datasets

I've saved an xml string into a file and loaded it into a
dataset then displayed it into a datagrid:

XmlDocument doc = new XmlDocument();
doc.loadXml(stringXml);
doc.Save(Server.MapPath("data.xml");
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("data.xml");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

I'm having issues because in some situations there is no
data, ie stringXml with be an empty file such as
<contacts />
The application I'm working in doesn't debug but just
gives me an application error.

Can someone help me still display an empty datagrid
without causing an error?

Thanks!
Nov 15 '05 #1
2 1327
"Sandy" <an*******@discussions.microsoft.com> wrote in news:016401c39999
$e****************@phx.gbl:
I've saved an xml string into a file and loaded it into a
dataset then displayed it into a datagrid:

XmlDocument doc = new XmlDocument();
doc.loadXml(stringXml);
doc.Save(Server.MapPath("data.xml");
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("data.xml");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

I'm having issues because in some situations there is no
data, ie stringXml with be an empty file such as
<contacts />
The application I'm working in doesn't debug but just
gives me an application error.

Can someone help me still display an empty datagrid
without causing an error?

Thanks!


Just open the xml file with XmlDocument. Check if there are ChildNodes. if
not, just don't set it on the dataset. if there are: directly hand the
xmlreader stream to the dataset.

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2
Why not use a try...catch block. This will catch errors like malformed XML at
the same time!

/steveA

On Thu, 23 Oct 2003 12:14:33 -0700, "Sandy"
<an*******@discussions.microsoft.com> wrote:
I've saved an xml string into a file and loaded it into a
dataset then displayed it into a datagrid:

XmlDocument doc = new XmlDocument();
doc.loadXml(stringXml);
doc.Save(Server.MapPath("data.xml");
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("data.xml");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

I'm having issues because in some situations there is no
data, ie stringXml with be an empty file such as
<contacts />
The application I'm working in doesn't debug but just
gives me an application error.

Can someone help me still display an empty datagrid
without causing an error?

Thanks!


Steve Alpert
my email Fg**********@vqk.pbz is encrypted with ROT13 (www.rot13.org)
-------------------------------------------
NOTICE OF CONFIDENTIALITY
-------------------------------------------
The information in this email, including attachments, may be confidential
and/or privileged and may contain confidential health information. This
email is intended to be reviewed only by the individual or organization
named as addressee. If you have received this email in error please
notify IDX immediately--by return message to the sender or to
se******@idx.com--and destroy all copies of this message and any
attachments. Please note that any views or opinions presented in this
email are solely those of the author and do not necessarily represent
those of IDX. Confidential health information is protected by state and
federal law, including, but not limited to, the Health Insurance
Portability and Accountability Act of 1996 and related regulations.
Nov 15 '05 #3

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

Similar topics

3
by: Mauricio Correa L. | last post by:
Hello, i have a string with a XML inside, but when a try lo load a dataset with the next code. Dim all As String = Webservice.getName(TextName.Text, TextNo2.Text).ToString 'this webmethod return...
4
by: Bill Stock | last post by:
The few times in the past that I've loaded unbound data, I've tended to cheat and use temp tables (not really unbound) or use code for small datasets. I'm currently involved in a project that...
4
by: Alpha | last post by:
I have a small Window application and through out the different forms I create a different dataset. At the begining I used the Tools to drag and drop the SqlDataAdapter, connection and dataset...
4
by: Paul | last post by:
I have a test application that uses databinding to a table of about 20,000 records. The SQL statement for the databinding is "SELECT * FROM tbl_CID_XRef". From this I can move forward and...
9
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
0
by: Chris | last post by:
Hello, I have a problem with re-loading datasets. As a simple example, if I have an SQL table of addresses comprising active and inactive addresss, I wish to load either sub-set by clicking on...
0
by: S.Tedeschi | last post by:
Hi all; as posted some days ago, I'm converting an on-line app; I used to heavily rely on strongly-typed DataSets directly dropped onto pages, and so viewed by code(-behind) as well. In the next...
12
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a...
9
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.