gpt4 book ai didi

c# - 从函数返回 2 个项目

转载 作者:行者123 更新时间:2023-11-30 19:12:20 24 4
gpt4 key购买 nike

我有一个存储过程,我将执行它的结果并将它传递到一个数据集中并返回它,但同时我的存储过程中有一个输出参数,我也想返回它,我怎样才能返回两个数据集以及我的函数的整数输出值,还是有更“合适的方法”来处理这种情况?请多多指教,谢谢。

Public Function SelectCampaignManagementTableListing(ByVal objCampaignManagmentClassBLL As CampaignManagementBLL, ByVal dbConnection As DbConnection, ByVal SortExpression As String, ByVal SortFilterText As String, ByVal SortFilterField As String, ByVal SortDirection As String, ByVal PageNumber As Integer, ByVal PageCount As Integer, ByVal TotalCount As Integer) As DataSet

Dim dbCommand As DbCommand = Nothing
Dim retDS As DataSet = Nothing

Try
If dbConnection.State <> ConnectionState.Open Then
dbConnection.Open()
End If

dbCommand = GetStoredProcedureCommand("Campaign_LoadListing")
dbCommand.Connection = dbConnection

With objCampaignManagmentClassBLL

Select Case SortFilterField
Case "Code"
AddInParameter(dbCommand, "@Code", DbType.String, 50, DBNull.Value)
dbCommand.Parameters("@Code").Value = SortFilterText
Case "Name"
AddInParameter(dbCommand, "@Name", DbType.String, 150, DBNull.Value)
dbCommand.Parameters("@Name").Value = SortFilterText
End Select


Select Case SortDirection
Case "True"
AddInParameter(dbCommand, "@SortOrder", DbType.Boolean, 1, DBNull.Value)
dbCommand.Parameters("@SortOrder").Value = True
Case "False"
AddInParameter(dbCommand, "@SortOrder", DbType.Boolean, 1, DBNull.Value)
dbCommand.Parameters("@SortOrder").Value = False
End Select

AddInParameter(dbCommand, "@SortOrder", DbType.String, 50, DBNull.Value)
If Not String.IsNullOrEmpty(SortDirection) Then
dbCommand.Parameters("@SortOrder").Value = SortDirection
End If

Select Case SortExpression
Case "Code"
'sortType = "@SortByCampaignCode"
AddInParameter(dbCommand, "@SortByCampaignCode", DbType.Boolean, 1, DBNull.Value)
dbCommand.Parameters("@SortByCampaignCode").Value = True
Case "Name"
'sortType = "@SortByCampaignName"
AddInParameter(dbCommand, "@SortByCampaignName", DbType.Boolean, 1, DBNull.Value)
dbCommand.Parameters("@SortByCampaignName").Value = True
Case "Priority"
AddInParameter(dbCommand, "@SortByPriority", DbType.Boolean, 1, DBNull.Value)
dbCommand.Parameters("@SortByPriority").Value = True

End Select

AddInParameter(dbCommand, "@PageNumber", DbType.Int32, 4, DBNull.Value)
If Not IsNothing(PageNumber) Then
dbCommand.Parameters("@PageNumber").Value = PageNumber
End If

AddInParameter(dbCommand, "@PageCount", DbType.Int32, 4, DBNull.Value)
If Not IsNothing(PageCount) Then
dbCommand.Parameters("@PageCount").Value = PageCount
End If

' Heres the output parameter
Dim objOutputParameter As New SqlParameter("@Return_TotalCount", SqlDbType.Int)
dbCommand.Parameters.Add(objOutputParameter)
objOutputParameter.Direction = ParameterDirection.Output

End With

' These are the 2 items I need to return.
retDS = ExecuteDataSet(dbCommand)
Dim tCount As Integer = CInt(dbCommand.Parameters("@Return_TotalCount").Value)

Catch ex As Exception
Throw New DALException(ex, dbCommand, Caching.GetCustomerCodeCookie(), "SelectCampaignManagementTableListing")
Finally

If Not dbCommand Is Nothing Then
dbCommand.Dispose()
End If
End Try
Return retDS
End Function

最佳答案

您有多种选择:

  1. 定义您自己的自定义类以公开您的输出属性,并返回该类的一个实例。
  2. 返回 System.Tuple 的实例包含您的输出值。
  3. 使用输出参数返回您的输出值。

关于c# - 从函数返回 2 个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7898585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com