我有类似的经历,这就是我管理它的方式。
使用SqlDbType.NVarChar
代替SqlDbType.Xml
如下图
DataSet dsWithSomeTable=new DataSet("NameSpace");
tblTable.TableName="Table";
dsWithSomeTable.Tables.Add(tblTable);
SqlParameter xml = new SqlParameter
{
ParameterName = "@XML",
SqlDbType = SqlDbType.NVarChar,
Value = dsWithSomeTable.GetXml()
};
在存储过程的另一端通过将其转换为 XML 类型来处理它
-- =============================================
-- Description: Inserts records from CE device
-- =============================================
CREATE PROCEDURE [Inventory].[uspCEInserXML]
@XML NVARCHAR(MAX) = NULL
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
--Receives parameter as NVarchar since the CE environment doesnt support XML type param
--and converting into XML
DECLARE @CXML XML=CAST(@XML AS XML)
SELECT
XTab.value('Col1[1]','int') AS[Col1],
XTab.value('Col2[1]','int') AS[Col2],
XTab.value('Col3[1]','float') AS[Col3]
INTO #TMP
FROM @CXML.nodes('NameSpace/Table') XTab([XTab])
END
GO