2013-01-13 53 views
0

使用SQL Server 2005瓦特/最新PetaPoco W /下面的代碼:PetaPoco輸出參數從存儲過程沒有返回

Dim count = New SqlParameter("@Count", System.Data.ParameterDirection.Output) 
    count.DbType = Data.DbType.Int32 

    Dim results = db.Query(Of User)(";exec SearchUserPaged @@[email protected], @@[email protected], @@[email protected], @@[email protected], @@[email protected] OUT", 
            New With {.page = pageEx, .maximumRows = maximumRowIndex, .ClientID = Me.ClientID, .SortExp = sortExpression, .Count = count}).ToList() 

    'Dim results = db.EDPEntities.Query(Of User)(";exec SearchUserPaged @@[email protected], @@[email protected], @@[email protected], @@[email protected], @@[email protected] OUTPUT", 
    '         pageEx, maximumRowIndex, Me.ClientID, sortExpression, count).ToList() 

    If IsDBNull(count.Value) Then 
     Me.Count = 0 
    Else 
     Me.Count = count.Value 
    End If 

但輸出參數總是返回相當新的PetaPoco值0。所以不知道如果我錯過了超級明顯的東西。

這裏是一個運行在查詢分析器通過精細地圖生成的SQL:

DECLARE @0 int,@1 int,@2 int,@3 nvarchar(4000),@4 int 
SET @0=1 
SET @1=25 
SET @2=10145 
SET @3=NULL 
SET @4=2 
exec SearchUserPaged @[email protected], @[email protected], @[email protected], @[email protected], @[email protected] OUT 

SELECT @4 

當我SELECT @4返回正確的值。

回答

0

這個工作(不知道爲什麼):

Dim count = New SqlParameter("@Count", System.Data.SqlDbType.Int) 
    count.Direction = System.Data.ParameterDirection.Output 
    count.Value = DBNull.Value 

    Dim results = db.Query(Of User)(";exec SearchUserPaged @@[email protected], @@[email protected], @@[email protected], @@[email protected], @@[email protected] OUT", New With { _ 
     Key .page = pageEx, _ 
     Key .maximumRows = maximumRowIndex, _ 
     Key .ClientID = ClientID, _ 
     Key .SortExp = sortExpression, _ 
     Key .Count = count _ 
    }).ToList() 

    If IsDBNull(count.Value) Then 
     Me.Count = 0 
    Else 
     Me.Count = count.Value 
    End If 
+0

什麼區別的默認值嗎? – Schotime

0

我認爲這是因爲帕拉姆

Dim count = New SqlParameter("@Count", System.Data.SqlDbType.Int) 
count.Direction = System.Data.ParameterDirection.Output 
count.Value = DBNull.Value -- this fixed the error. 

希望這有助於

相關問題