Link to home
Start Free TrialLog in
Avatar of trevorhartman
trevorhartmanFlag for United States of America

asked on

dataset getxml/writexml

Hi,

I have a dataset and need to return it as XML.  I can do this using GetXml or WriteXml, but both of those do not include null columns.  How can I make my null columns show up as empty elements?

Thanks - Trevor
Avatar of raterus
raterus
Flag of United States of America image

Check the bottom of this article, this is a guess, but I'm fairly confident it will work.  If you use a typed dataset, and set the nullvalue to an empty string I believe it will export properly.
Avatar of trevorhartman

ASKER

i'm not using a typed dataset..
i'm not even sure what that is
ASKER CERTIFIED SOLUTION
Avatar of laotzi2000
laotzi2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of laotzi2000
laotzi2000

SqlDataAdapter da = new SqlDataAdapter(
     "select * from authors",
     "server=localhost;uid=sa;database=pubs");
DataSet ds = new DataSet();

da.Fill(ds, "authors");
ds.WriteXmlSchema("myauthors.xsd");
ahh, and then you use ReadXMLSchema if you ever load the DataSet from xml, and the dataset will know that missing elements are null, cool
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
very interesting stuff, thanks guys
well looks like i'll need to refresh my xsd..
using XSD, is there any way i can force it to write empty elements?
maybe you could set any null values to "" before you write out the xml
set them to "" by recursing through the rows of the datatable?  or is there a better way?