Question

I execute a procedure and fill the values in a DataSet. Procedure returns XML datatype values. When I convert the DataSet to XML, I get the XML datatype values as string but I want it as child nodes. How do I do this?

Procedure Outputs:

enter image description here

I convert DataSet to XML as below

DataSet ds = null;
using (SqlConnection connection = new SqlConnection(sConnectionString))
{
    connection.Open();
    SqlCommand Sqlcommand = new SqlCommand();
    Sqlcommand.CommandType = CommandType.StoredProcedure;
    if (SqlParamlist != null)
    {
        foreach (SqlParameter Sqlparameter in SqlParamlist)
        {
            Sqlcommand.Parameters.AddWithValue(Sqlparameter.ParameterName, Sqlparameter.Value);                                
        }
    }
    Sqlcommand.CommandText = sProc;
    Sqlcommand.Connection = connection;
    sProcParams = sProc + " " + sProcParams;
    using (SqlDataAdapter da = new SqlDataAdapter(Sqlcommand))
    {
        ds = new DataSet("DATATABLE");
        da.Fill(ds, "DATAROW");
        Sqlcommand.Parameters.Clear();
        da.Dispose();
    }
    connection.Close();
}
XmlDataDocument xDoc = new XmlDataDocument();
xDoc.LoadXml(ds.GetXml());

Here's what my xDoc.OuterXml has

<DATATABLE>
    <DATAROW>
        <xmllimes>&lt;row&gt;&lt;time&gt;16:00:00&lt;/time&gt;&lt;/row&gt;</xmllimes>
    </DATAROW>
    <DATAROW>
        <xmllimes>&lt;row&gt;&lt;time&gt;14:20:00&lt;/time&gt;&lt;/row&gt;</xmllimes>
    </DATAROW>
    <DATAROW>
        <xmllimes>&lt;row&gt;&lt;time&gt;12:30:00&lt;/time&gt;&lt;/row&gt;</xmllimes>
    </DATAROW>
</DATATABLE>

but I want ds.GetXML() to return the following

<DATATABLE>
    <DATAROW>
        <xmllimes>
            <row>
                <time>16:00:00</time>
            </row>
        </xmllimes>
    </DATAROW>
    <DATAROW>
        <xmllimes>
            <row>
                <time>14:20:00</time>
            </row>
        </xmllimes>
    </DATAROW>
    <DATAROW>
        <xmllimes>
            <row>
                <time>12:30:00</time>
            </row>
        </xmllimes>
    </DATAROW>
</DATATABLE>

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top