title: How to store userid in session using vb.net
body: <p>How to store user id in session so that I can use in other pages?</p>
  
  <p>My code is as follows</p>
  
  <pre><code>Imports System.Data
  Imports System.Data.SqlClient
  Imports System.Data.OleDb
  Imports System.Web
  Imports System.IO
  
  Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      cnn.Open()
  
      Dim sqlcomm2 As New SqlCommand("Select * from Users where userid='" &amp; txtuserid.Text &amp; "'", cnn)
      Dim r2 As SqlDataReader = sqlcomm2.ExecuteReader()
      While r2.Read
          Dim UserId1 As String = Trim(UCase(CStr(r2("UserId"))))
          Dim Password As String = Trim(UCase(CStr(r2("Password"))))
          Dim username As String = CStr(r2("Name"))
  
          Session("User") = UserId1
          Session("Password") = Password
  
          'System.Web.HttpContext.Current.Session("item")
  
      End While
      r2.Close()
  </code></pre>
  
  <p>but its showing error as:</p>
  
  <blockquote>
    <p>session is not declared</p>
  </blockquote>