This is my parameter definition:
var param = new SqlParameter
{
ParameterName = "@param",
SqlDbType = SqlDbType.Xml,
Direction = ParameterDirection.Output,
Size = int.MaxValue
};
command.Parameters.Add(param);
Then I do:
command.ExecuteNonQuery();
And finally:
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
return serializer.Deserialize(
new MemoryStream(Encoding.UTF8.GetBytes(param.Value.ToString())))
as MyClass;
Do I really need to convert to string and then byte array?
Use
Parameter.SqlValue
, will return aSqlXml
instance and you can useCreateReader
to get an XML reader. Then use theXmlSerializer.Deserialize(XmlReader)
overwrite.If the XML is large, you should consider using
CommandBehavior.SequentialAccess
.