title: ASP.NET assigning an integer value pulled from database to a variable and using it for if/else check
body: <p>I'm having this bit of problem I'm hoping someone will be able to point me in the right direction as I don't have much hair left to pull out anymore. </p>
  
  <p>I'm writing this ASP.NET program which has a Login Page and I need to fetch an integer value from the database after username/password authentication (which I was able to manage) and run it through an if/else block to determine the page to which I will be redirecting the user. My problem begins there. </p>
  
  <p>By walking through the code I found out that after the fetching, it seems like the assignment was successfully done but the assigned value is the password i acquired earlier. So when it comes to the if/else block, none of the options match and it falls to the else option failing to redirect to the necessary page. I am using the same query variable I used when fetching the password from the database, just ediiting its value before executing the command. Here is the code:</p>
  
  <pre><code>query = String.Format("SELECT u_accesslevel FROM users WHERE u_email='{0}';", username);
  int accesslevel = Convert.ToInt32(command.ExecuteScalar());
  </code></pre>
  
  <p>This is where I execute the query and assign the variable. And: </p>
  
  <pre><code>if (accesslevel == 1)
  {
       Response.Redirect("Page1.aspx");
  }
  else if (accesslevel == 2)
  {
       Response.Redirect("Page2.aspx");
  }
  else if (accesslevel == 3)
  {
       Response.Redirect("Page3.aspx");
  }
  else
       Response.Write("ERROR!");
  </code></pre>
  
  <p>I'm using OleDbConnection to connect to the database and I'm using an Access database file to hold the data. </p>
  
  <p>For additional details about the project and myself, there is no concern for security. It is for a school project which won't be opened again after its grading. I just need to get the program running. While I have some programming experience with C# (no database interaction though), ASP.NET and web technologies in general are new ground for me and I'm not entirely sure what I'm doing. Is there a better way to do this instead of using .ExecuteScalar()?</p>
  
  <p>PS: I'm also fetching the user id from the same table and using the same assignment operation to create a session object for the user before they are redirected to their requested page. I can't be sure if that one works correctly either because of the problem above. The piece of code for that is: </p>
  
  <pre><code>int userid = Convert.ToInt32(command.ExecuteScalar());
  Session["_id"] = userid.ToString();
  </code></pre>
  
  <p>I'd be grateful if you could check if that's correct as well, since its practically the same thing (or looks like it). Thanks!</p>