0

Im working on an app for windows CE and trying to access a stored procedure in SQL server.

I need to pass XML parameter but its giving me the following runtime exception :

Invalid SqlDbType enumeration value: 25

at this line :

SqlParameter XMLDoc = new SqlParameter("@XMLDoc", SqlDbType.Xml);

Same code works in normal .net framework so I guess its something specific to compact framework.

msdn says its supported for compact framework.

Any help would be appreciated.

1 Answer 1

1

I had similar experience and this is how I managed it.

Use SqlDbType.NVarChar instead of SqlDbType.Xml as shown below

DataSet dsWithSomeTable=new DataSet("NameSpace");
tblTable.TableName="Table";
dsWithSomeTable.Tables.Add(tblTable);

  SqlParameter xml = new SqlParameter
            {
                ParameterName = "@XML",
                SqlDbType = SqlDbType.NVarChar,
                Value = dsWithSomeTable.GetXml()
            };

And on the other end in stored procedure handle it by converting it to XML type

-- =============================================
-- 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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.