Avatar of Cobra967
Cobra967
Flag for United States of America asked on

Store single record two values to ASP. NET Session using a Function running a ExecuteReader by executing a Sql Stored Procedure

Hello, I have a Sql Server stored procedure that return a single record with two columns in it (Role_Id and Program_Id). I currently have a function in Asp.Net VB.Net that will execute the Stored procedure and return the Role_Id and then store the result in a Session. However, from the same Function I would like to retrieve the Role_Id and the Program_Id and store the Program_Id in a different session. How do I accomplish this (I already managed for the stored procedure to return both values - Both Integers)?

       Session("ProgramId") = GetRole(?)

        Session("UserRole") = GetRole()

Private Function GetRole() As Int32
        Try

            Dim con As SqlConnection = GetSqlConnection()
            Dim cmd As New SqlCommand() With {.CommandText = "GetRole", .CommandType = CommandType.StoredProcedure, .Connection = con}
            cmd.Parameters.Add(New SqlClient.SqlParameter("@UserName", Session.Item("EmployeeId")))
            con.Open()
            Dim Role As Int32 = DirectCast(cmd.ExecuteScalar(), Int32)
            Return Role
            con.Close()

        Catch generatedExceptionName As Exception
            'HttpContext.Current.Response.Redirect("~/ErrorRedirect.aspx", False)

        End Try

    End Function

Open in new window

ASP.NETMicrosoft SQL Server

Avatar of undefined
Last Comment
Cobra967

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Paul MacDonald

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Cobra967

ASKER
Excellent! Thank you vey much.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck