Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,I need to export a DataSet to XML but every column with DBNull value disappears from the final xml file!

myDataAdapter.Fill(myDataSet, "info" ); myDataSet.WriteXml(dirpc + @"\gfmfinfo.xml" ); 

I need to find a way of replacing every DBnull value after the Fill  so that every column appeares in the xml file. Any sugestions?
Posted
Updated 6-Feb-10 2:08am
v5

I guess the obvious, brute force method is out of hte question ? How about sanitising your data at the point that you request it from the database ?

 
Share this answer
 
Here's one thing you could do. Are you using SQL to fill this dataset? If so, then you can write the SQL statement to handle the cases directly. Use the ISNULL function. So a sample statement would be...

SELECT FieldThatWontBeNULL, ISNULL(FieldThatMightBeNULL,'Null Replacement') as FieldThatMightBeNULL FROM MyTable


Then your dataset doesn't need to worry about this. If you need to set this replacement value dynamically, you can just build it into your SQL statement if you are building as a string, or set it up as a parameter if you're going via a stored procedure.
If you still need help, let us know
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900