0

使用带有最新 PetaPoco 的 SQL Server 2005 和以下代码:

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

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

    'Dim results = db.EDPEntities.Query(Of User)(";exec SearchUserPaged @@page=@0, @@maximumRows=@1, @@ClientID=@2, @@orderBy=@3, @@Count=@4 OUTPUT",
    '                                  pageEx, maximumRowIndex, Me.ClientID, sortExpression, count).ToList()

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

但是输出参数总是返回 0 值。对 PetaPoco 来说很新,所以不确定我是否遗漏了一些非常明显的东西。

这是 Peta 生成的 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 @page=@0, @maximumRows=@1, @ClientID=@2, @orderBy=@3, @Count=@4 OUT

SELECT @4

当我SELECT @4返回正确的值时。

4

2 回答 2

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 @@page=@page, @@maximumRows=@maximumRows, @@ClientID=@ClientID, @@orderBy=@SortExp, @@Count=@Count 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
于 2013-01-14T05:21:48.840 回答
0

我认为这是因为 Param 的默认值

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

希望这可以帮助

于 2014-03-14T07:04:40.573 回答