2015-03-13 88 views
0

我有什麼似乎是一個常見問題,但沒有任何明顯的錯誤。過程或函數期望沒有提供參數 - 但參數WAS提供

我已經看過所有相關的主題,我可以看到與我的問題沒有任何相似之處,因爲我沒有犯任何「明顯的」錯誤,至少與其他人不相似。

我的存儲過程聲明:

CREATE PROCEDURE [dbo].[sp_AddEventTemp] 
    @iUserID int, 
    @iVerb int, 
    @iObject int, 
    @iResult int, 
    @nTransactionID numeric Output 

,代碼:

var userId = 9530; 
var verb = 2; 
var objectId = 15; 
var transactionId = 0; 

using (var connection = new SqlConnection(ConnectionString())) 
{ 
    var command = new SqlCommand('sp_AddEventTemp', connection) 
    { 
     CommandType = CommandType.StoredProcedure 
    }; 

    command.Parameters.Add(new SqlParameter("@iUserID", userId) 
    { 
     Direction = ParameterDirection.Input, 
     SqlDbType = SqlDbType.Int 
    }); 
    command.Parameters.Add(new SqlParameter("@iVerb", verb) 
    { 
     Direction = ParameterDirection.Input, 
     SqlDbType = SqlDbType.Int 
    }); 
    command.Parameters.Add(new SqlParameter("@iObject", objectId) 
    { 
     Direction = ParameterDirection.Input, 
     SqlDbType = SqlDbType.Int 
    }); 
    command.Parameters.Add(new SqlParameter("@iResult", 0) 
    { 
     Direction = ParameterDirection.Input, 
     SqlDbType = SqlDbType.Int 
    }); 
    command.Parameters.Add(new SqlParameter("@nTransactionID", 0) 
    { 
     Direction = ParameterDirection.Output, 
     SqlDbType = SqlDbType.Int 
    }); 

    // execute 
    connection.Open(); 

    transactionId = (int)command.ExecuteScalar(); 

    connection.Close(); 
} 

return transactionId; 

我也得到:

Procedure or function 'sp_AddEventTemp' expects parameter '@iResult' which was not supplied 

即使它顯然是供應!

我做了這個測試通過直接的SQL服務器上運行此:

sp_AddEventTemp 9530, 2, 15, 0, 0 

它完美地工作。我得到了:(1 row(s) affected)

因此,存儲過程本身沒有任何問題。代碼中必須有一些東西,我無法弄清楚,因爲它看起來對我來說是正確的。

我對其他類似的存儲過程做同樣的事情,他們都工作正常。

任何想法?

在此先感謝

回答

0

難道是某種形式的後續錯誤的,由於程序的數據類型爲@nTransactionID和你的代碼(數字/ INT)的它的使用之間的不匹配?

+0

不要這樣想,因爲沒有SqlDbType.Numberic這樣的東西 這對我來說仍然是一個謎,但我通過使用解決方法得到它的工作 – Nick 2015-03-18 10:19:44

相關問題