Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:08:48+00:00 2026-05-26T21:08:48+00:00

the code i’m using is below. Is this the proper way to use Session?

  • 0

the code i’m using is below. Is this the proper way to use Session? also how do I call companyID and userID to clarify, if i did Session. is it Session.Contents or Session.Keys? this is my first time using session, I know I use httpcontact.current.user to access most of this but i’m not sure how to access each part of the data.

Thanks!

    MySqlConnection cn = new MySqlConnection("Server=localhost;Database=users; User=root;Password=00;");
    cn.Open();

    string storedProcedureName = "VLID";
    MySqlCommand cmd = new MySqlCommand(storedProcedureName, cn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@userName", this.Login1.UserName);
    cmd.Parameters.Add("@passwordID", this.Login1.Password);
    MySqlDataReader dr = cmd.ExecuteReader();

    if (dr.HasRows)
    {
        dr.Read();
        string userID = dr["userID"].ToString();

        string companyID = dr["CompanyID"].ToString();
        string sessionID = Session.SessionID.ToString();
        Session.Add(companyID, "companyID");
        Session.Add(userID, "userID");
        e.Authenticated = true;
        Response.Redirect("index.html");
        // Event Authenticate is true  
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:08:48+00:00Added an answer on May 26, 2026 at 9:08 pm

    You are calling Session.Add method a little backwards:

    Session.Add takes a key and a value, in that order; therefore, on your code you want:

    Session.Add("companyID",companyID );
    Session.Add("userID",userID );
    

    But instead, you could do this, too:

    Session["companyID"]=companyID;
    Session["userID"]=userID;
    

    Then, whenever you need to retrieve the userID value that you stored previously, you can do:

    string userID= Session["userID"] as string;
    

    As a side note, I wouldn’t mix data access code on the UI code as you are doing.

    The code that gets the data from the database should be moved to the data access layer (DAL).

    And when you instantiate a database connection, always enclose it in an using statement so that is properly disposed when it comes out of scope:

    using(MySqlConnection cn = new MySqlConnection("Server=localhost;Database=users; User=root;Password=00;"))
    {
        cn.Open();
        //rest of the code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

code below. i'm tryind to obtain string answers like a1, c4 this is what
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
Code like this often happens: l = [] while foo: # baz l.append(bar) #
Code Used: m_pButton->Create(LABC, WS_CHILD | WS_VISIBLE| BM_SETIMAGE,CRect(0,0,100,100),this,ID_BUTTON1); m_pButton->SetIcon(::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1))); //above Code show neither showing
Code: //create the animation. $('img#header').hover(function(){ $(this).animate({top: -10px }, slow); I am trying to have
Code #include <iostream> using namespace std; int main() { const int N = 22;
Code: $(#telecomGrayscale, this).stop().animate({ top: '467px' }, { duration: 400 }).delay(800).queue(function() { $(#boxcaptionTelecom, this).stop().animate({ top:
code below for a simple auto suggest box... however when I click a suggestion
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.