title: How do I get this database interaction working? I keep trying and it keeps throwing exceptions
body: <p>I'm a student. Don't worry, my lack of skills are currently not a detriment to any professional organization.</p>
  
  <p>I'm trying to set up a password system based on a database right now. There's a lot of elements to go, but right now I just want to call some data and insert it into my project. </p>
  
  <p>Currently I'm getting NullReferenceException at  if (dr.Read())</p>
  
  <p>The relevent code would be:</p>
  
  <pre><code>       string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=access.mdb";
      SqlConnection conn;
      SqlCommand cmd;
      SqlDataReader dr;
      DataTable dt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>        if (e.KeyCode == Keys.Enter)
          {
              e.Handled = true;
              e.SuppressKeyPress = true;
  
              try
              {
                  conn = new SqlConnection(strConnectionString);
                  cmd = new SqlCommand("select PASSWORD from regulate where NAME = @ID", conn);
                  cmd.Parameters.AddWithValue("@ID", txtName.Text);
                  conn.Open();
                  dr = cmd.ExecuteReader();
              }
              catch
              { }
              if (dr.Read())
              {
                  txtVaries.Text = dr["PASSWORD"].ToString();
              }
              conn.Close();
  
              if (txtVaries.Text == txtPW.Text)
              {
                  tabControl1.TabPages.Remove(tabPW);
                  tabControl1.TabPages.Remove(tabMain);
                  tabControl1.TabPages.Insert(0, tabEdit);
              }
  </code></pre>