2013-01-13 57 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. 

希望这有助于

相关问题