Created
April 6, 2015 04:52
-
-
Save Microsofttechies/1a48cd313775967253b8 to your computer and use it in GitHub Desktop.
dataSet.GetXml() doesn't return xml for null or blank columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| First clone the DataTable, make all columns of type string, replace all null values with string.empty, then call GetXml on a new DataSet. | |
| //First bind XML data in to data set..objDataSet | |
| DataTable dt = objDataSet.Tables[0]; | |
| DataTable dtCloned = dt.Clone(); | |
| foreach (DataColumn dc in dtCloned.Columns) | |
| dc.DataType = typeof(string); | |
| foreach (DataRow row in dt.Rows) | |
| { | |
| dtCloned.ImportRow(row); | |
| } | |
| foreach (DataRow row in dtCloned.Rows) | |
| { | |
| for (int i = 0; i < dtCloned.Columns.Count; i++) | |
| { | |
| dtCloned.Columns[i].ReadOnly = false; | |
| if (string.IsNullOrEmpty(row[i].ToString())) | |
| row[i] = string.Empty; | |
| } | |
| } | |
| DataSet ds = new DataSet(); | |
| ds.Tables.Add(dtCloned); | |
| string xml = ds.GetXml(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment