Link to home
Create AccountLog in
Avatar of Cobra967
Cobra967Flag 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

            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")))
            Dim Role As Int32 = DirectCast(cmd.ExecuteScalar(), Int32)
            Return Role

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

        End Try

    End Function

Open in new window

Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Cobra967


Excellent! Thank you vey much.