Convert dataset to xml
How to convert dataset to xml with db null values
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manish Kumar ChoudharyPosted Mar 13, 2015, 7:25 AM
try
{
StringWriter sw = new StringWriter();
//ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);
DataTable dt = ds.Tables[0];
sw.Write(@"
foreach (DataRow row in dt.Rows)
{
sw.Write(@"
foreach (DataColumn col in dt.Columns)
{
sw.Write(@"<" + XmlConvert.EncodeName(col.ColumnName) + @">");
sw.Write(row[col]);
sw.Write(@"" + XmlConvert.EncodeName(col.ColumnName) + @">");
}
sw.Write(@"
}
sw.Write(@"
return sw.ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}