title: Login using database authentication
body: <pre><code>namespace Project
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          OleDbConnection MyCon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Project.accdb");
  
          public string user;
          string password;
          public MainWindow()
          {
  
              InitializeComponent();
  
          }
  
          private void button2_Click(object sender, RoutedEventArgs e)
          {
              user = textBox1.Text;
              char firstLetter = user[0];
              string password = textBox2.Text;
              MyCon.Open();
              string command = "Select Name from Login where userid=@userid AND password = @password";
              OleDbCommand cmd = new OleDbCommand(command, MyCon);
              cmd.Parameters.AddWithValue(@user, textBox1.Text);
              cmd.Parameters.AddWithValue(@password, textBox2.Text);
              OleDbDataReader dr = cmd.ExecuteReader();
              int id = cmd.Parameters[0].Value; // This line genrating error
            //  MessageBox.Show(user);
              if (firstLetter == 'E' )
              {
                  if (dr.Read() == true )
                  {
  
                      Window1 w1 = new Window1();
                      w1.textBox3.Text = user;
                      w1.textBox4.Text = dr[0].ToString();
                      w1.Show();
                      this.Close();
  
                      }
                      else
                      {
                          MessageBox.Show("NOt Login");    
  
                      }
                  }
  </code></pre>
  
  <p>How do I retrieve id and then match id and password to user login? My Code has problems. If I give wrong id  but correct password then user can login. This does not happen if id and password are both wrong; user cannot Login..</p>