6. April 2012 14:00
DataSet has one convenient function to export to XML string but when the record has DBNULL value , the xml element will be omitted from the XML output . It took a while to search from framework document and google here and there , unfortunately there is no perfect way to achieve .
For SQL server, one workaround is to check if column value is DBNull then set the column value to empty string no matter what original column data type is , but this workaround does not work for Oracle . It depends on column type . If it is varchar type then it can set column value to empty string then empty XML element can be exported . If column is other type , then it will throw out an running exception .
In the end there is no better way so has to write a custome function to loop dataset tables to export to XML string with all elements included ,but performance is not tested fully when compare with native dataset exportXML function.
Just wonder like many other guys why this feature is not provided natively in current DOTNET framework .