Sunday, March 1, 2015

Parsing XML with .ReadXml

Not using the ReadXml method directly but you could just add the values yourself by looping through the colums and rows of the populated DataTable like this:



DataSet ds = new DataSet();
System.IO.StringReader sr = new System.IO.StringReader(strXML);
ds.ReadXml(sr);

foreach (DataColumn column in ds.Tables[0].Columns)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
if (string.IsNullOrEmpty(row[column.ColumnName].ToString()))
{
//add default value instead of NULL here
row[column.ColumnName] = "1";
}
}
}





Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


No comments:

Post a Comment