Reputation: 1794
During fetching of data in C#, how can we store the XML file returned from a SQL Server stored procedure into a string
or var
?
My code:
SqlDataReader rdr = SqlHelper.ExecuteReader(Conn, CommandType.StoredProcedure, spName, ListParam.ToArray());
My query is
select *
from table_Name
FOR XML AUTO, ROOT ('Collection');
Upvotes: 1
Views: 116
Reputation: 164
Edited as per the OP's request.
StringBuilder sb = new StringBuilder();
using (var reader = SqlHelper.ExecuteXmlReader(Conn, CommandType.StoredProcedure, spName, ListParam.ToArray()))
{
if (reader == null) return;
while(reader.Read())
{
sb.AppendLine(reader.ReadOuterXml());
}
string xmlVal = sb.ToString(); // You can get the xml as string here.
}
Upvotes: 1