Results 1 to 5 of 5

Thread: [RESOLVED] Return values from PROC to VB.NET application to display on labels.

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Return values from PROC to VB.NET application to display on labels.

    I have created a PROC and it gets all the information, but not in a table (not sure why). But, I need to return the values and then display those values in labels.

    This is what I have so far. I am not sure what I am doing and have been on Google all night trying to figure it out.
    Code:
    ALTER PROCEDURE [dbo].[SP_GetTicketCountByStatus]
    (
    @CreatedBy AS VARCHAR(250)
    )
    AS
    
    DECLARE @MyCount AS INT
    DECLARE @OpenCount AS INT
    DECLARE @PendingCount AS INT
    DECLARE @WaitingResponseCount AS INT
    DECLARE @WorkInProgressCount AS INT
    
    SET NOCOUNT ON
    
    BEGIN
    SELECT @MyCount = COUNT(*)
    FROM [TicketManager].[dbo].Tickets AS TM
    WHERE TM.TicketStatus <> 'Resolved' AND TM.CreatedBy = @CreatedBy
    RETURN @MyCount
    END
    
    BEGIN
    SELECT @OpenCount = COUNT(*)
    FROM [TicketManager].[dbo].Tickets AS TM
    WHERE TM.TicketStatus = 'Open'
    RETURN @OpenCount
    END
    
    BEGIN
    SELECT @PendingCount = COUNT(*)
    FROM [TicketManager].[dbo].Tickets AS TM
    WHERE TM.TicketStatus = 'Pending'
    RETURN @PendingCount
    END
    
    BEGIN
    SELECT @WaitingResponseCount = COUNT(*)
    FROM [TicketManager].[dbo].Tickets AS TM
    WHERE TM.TicketStatus = 'Waiting Response'
    RETURN @WaitingResponseCount
    END
    
    BEGIN
    SELECT @WorkInProgressCount = COUNT(*)
    FROM [TicketManager].[dbo].Tickets AS TM
    WHERE TM.TicketStatus = 'WorkInProgress'
    RETURN @WorkInProgressCount
    END
    Code:
            Using SetDatabaseConnection As New SqlConnection(MSSQLConnection)
                Try
                    Dim GetTicketCounts As SqlCommand = New SqlCommand
    
                    SetDatabaseConnection.Open()
    
                    With GetTicketCounts
                        .Connection = SetDatabaseConnection
                        .CommandType = CommandType.StoredProcedure
                        .CommandText = "SP_GetTicketCountByStatus"
                        .Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = MDIContainer.PersonsName.Text
                        .Parameters("@CreatedBy").Direction = ParameterDirection.Input
    
                        .Parameters("@MyCount").Direction = ParameterDirection.Output
                        .Parameters("@OpenCount").Direction = ParameterDirection.Output
                        .Parameters("@PendingCount").Direction = ParameterDirection.Output
                        .Parameters("@WaitingResponseCount").Direction = ParameterDirection.Output
                        .Parameters("@WorkInProgressCount").Direction = ParameterDirection.Output
    
                        Dim RetVal As Integer = CInt(.ExecuteScalar)
                    End With
    
                    Dim Ds As DataSet = New DataSet
                    Dim Da As SqlDataAdapter = New SqlDataAdapter(GetTicketCounts)
                    Ds.Clear()
                    Da.Fill(Ds)
    
                    With Ds.Tables(0)
                        If .Rows.Count > 0 Then
                            For Each TheDataRow As DataRow In .Rows
                                TicketsByStatusMine.Text = "Mine: " & CStr(TheDataRow.Item("MyCount"))
                                TicketsByStatusOpen.Text = "Open: " & CStr(TheDataRow.Item("OpenCount"))
                                TicketsByStatusPending.Text = "Pending: " & CStr(TheDataRow.Item("PendingCount"))
                                TicketsByStatusWaitingResponse.Text = "Waiting Response: " & CStr(TheDataRow.Item("WaitingResponseCount"))
                                TicketsByStatusWorkInProgress.Text = "Work in Progress: " & CStr(TheDataRow.Item("WorkInProgressCount"))
                            Next TheDataRow
                        End If
                    End With
                Catch CastEx As InvalidCastException
                    MessageBox.Show(CastEx.Message, _
                                    "Invalid Cast Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Catch ArgEx As ArgumentException
                    MessageBox.Show(ArgEx.Message, _
                                    "Argument Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Catch NullRefEx As NullReferenceException
                    MessageBox.Show(NullRefEx.Message, _
                                    "Null Reference Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Catch SQLEx As SqlException
                    MessageBox.Show(SQLEx.Message, _
                                    "SQL Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Catch FormatEx As FormatException
                    MessageBox.Show(FormatEx.Message, _
                                    "Format Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Catch OverflowEx As OverflowException
                    MessageBox.Show(OverflowEx.Message, _
                                    "Overflow Exception", _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error, _
                                    MessageBoxDefaultButton.Button1)
                Finally
                    SetDatabaseConnection.Close()
                End Try
            End Using
    Error is in the screenshot.
    What I need to do is get the counts and display each one in particular labels.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width