loading xml into datasets

  • Thread starter Thread starter Sandy
  • Start date Start date
S

Sandy

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!
 
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.
 
Why not use a try...catch block. This will catch errors like malformed XML at
the same time!

/steveA

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 (e-mail address removed) 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
(e-mail address removed)--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.
 
Back
Top