We help IT Professionals succeed at work.
Get Started

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

Cobra967
Cobra967 asked
on
144 Views
Last Modified: 2017-04-27
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

Comment
Watch Question
Director, Information Systems
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE