Convert dataset to xml
How to convert dataset to xml with db null values
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 13, 2015, 3:25 AM EDT
{
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();
}
}