How can I handle Xml output from a stored procedure in c# code?

  • Thread starter Thread starter c-sharp-coder
  • Start date Start date
C

c-sharp-coder

Guest
I have a stored procedure that returns a chunk of XML (over 1 million characters).
I am using the code below to get this XMl.

var xmlDocument = new XmlDocument();
var conn = new SqlConnection(DBConnectionString);
conn.Open();
var quoteLineParam = new SqlParameter()
{
ParameterName = "@Id",
SqlDbType = SqlDbType.Int,
Value = quoteLineId,
Direction = ParameterDirection.Input
};
var command = new SqlCommand
{
Connection = conn,
CommandText = "usp_GetXml",
CommandTimeout = 400,
CommandType = CommandType.StoredProcedure
};
command.Parameters.Add(quoteLineParam);
var sqlDataAdapter = new SqlDataAdapter(command);
var dataTable = new DataTable("xmloutput");
sqlDataAdapter.Fill(dataTable);
conn.Close();
var stringBuilder = new StringBuilder();
foreach (DataRow dr in dataTable.Rows)
{
stringBuilder.Append(dr[0].ToString());
}
string strOut = stringBuilder.ToString();
xmlDocument.LoadXml(strOut);



How can I get the entire XML in a single row without having to loop through the resultset?
Is this the default c# behavior.

Continue reading...
 
Back
Top