Calling a Stored Procedure with XML Datatype

前端 未结 9 1228
旧巷少年郎
旧巷少年郎 2021-01-05 07:06

I am simply trying to call a store procedure (SQL Server 2008) using C# and passing XMLDocument to a store procedure parameter that takes a SqlDbType.Xml data type. I am ge

9条回答
  •  既然无缘
    2021-01-05 07:56

    Or, with the fewest lines of code, read your XmlDocument straight into an XmlNodeReader and use that to initialise you SqlXml parameter value:

    SqlXml sqlXml= new SqlXml(new XmlNodeReader(doc));
    cmd.Parameters.Add("@FileContent", sqlXml);
    
    

    Note that you don't need to add the parameter with the type, then set the value - if you pass a type which SqlParameter recognises (in this case a SqlXml object), the type will be inferred.

提交回复
热议问题