2012-08-27 56 views
0

我有一個存儲在數據庫表中的XML,我試圖在下面檢索(變量strXML)。任何理由爲什麼這是空白?請幫忙。當我直接在數據庫中執行該過程時,它工作正常。XML不是由列類型XML返回

 try 
     { 
      // Open the database connection 
      using (SqlConnection myConn = my.openConnection("~",PConnectionString")) 
      { 
       // Initialize the SQL command object. 
       using (SqlCommand myCOmmand = new SqlCommand("getCycleXML", myConn)) 
       { 
        myCOmmand.CommandType = CommandType.StoredProcedure; 
        // Add the parameters 

        SqlParameter parameter2 = new SqlParameter("@emailID", SqlDbType.NVarChar, 128); 
        parameter2.Value = strEmailID; 
        parameter2.Direction = ParameterDirection.Input; 
        myCOmmand.Parameters.Add(parameter2); 

        SqlParameter parameter1 = new SqlParameter("@pCode", SqlDbType.VarChar, 50); 
        parameter1.Value = strPCode; 
        parameter1.Direction = ParameterDirection.Input; 
        myCOmmand.Parameters.Add(parameter1); 

        SqlParameter parameter7 = new SqlParameter("@cID", SqlDbType.Int); 
        parameter7.Direction = ParameterDirection.Input; 
        parameter7.Value = icID; 
        myCOmmand.Parameters.Add(parameter7); 

        SqlParameter parameter9 = new SqlParameter("@cycleXML", SqlDbType.Xml); 
        parameter9.Direction = ParameterDirection.Output; 
        myCOmmand.Parameters.Add(parameter9); 


        SqlParameter parameter10 = new SqlParameter("@msg", SqlDbType.VarChar, 50); 
        parameter10.Direction = ParameterDirection.Output; 
        myCOmmand.Parameters.Add(parameter10); 

        SqlParameter parameter11 = new SqlParameter("@Success", SqlDbType.Int); 
        parameter11.Direction = ParameterDirection.Output; 
        myCOmmand.Parameters.Add(parameter11); 
        //Execute the command 

        myCOmmand.ExecuteNonQuery(); 
        // Read the values of the output parameters 
        strXML = myCOmmand.Parameters["@cycleXML"].Value.ToString(); 

        ================================================= 

存儲過程定義如下:

USE [DMac] 
    GO 

    SET ANSI_NULLS ON 
    GO 
    SET QUOTED_IDENTIFIER ON 
    GO 

    CREATE PROCEDURE [dbo].[getCycleXML] 
    @emailID Nvarchar(128), 
    @cID varchar(50), 
    @pCode varchar(50), 
    @cycleXML xml output, 
    @Success int output, 
    @msg varchar(50) output 

    AS 
    BEGIN 
    select XMLDefectCycle from dbo.CycleXML where [email protected] and [email protected] and [email protected] 
    END 

============================= =

爲什麼代碼會以空白XML的形式返回。我檢查了數據庫中給定的參數,我期望從數據庫獲得一個XML。

回答