trevorhartman
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
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
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.
ASKER
i'm not using a typed dataset..
ASKER
i'm not even sure what that is
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SqlDataAdapter da = new SqlDataAdapter(
"select * from authors",
"server=localhost;uid=sa;d atabase=pu bs");
DataSet ds = new DataSet();
da.Fill(ds, "authors");
ds.WriteXmlSchema("myautho rs.xsd");
"select * from authors",
"server=localhost;uid=sa;d
DataSet ds = new DataSet();
da.Fill(ds, "authors");
ds.WriteXmlSchema("myautho
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very interesting stuff, thanks guys
ASKER
well looks like i'll need to refresh my xsd..
ASKER
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
ASKER
set them to "" by recursing through the rows of the datatable? or is there a better way?