title: How do I connect a MS Access database with a password and a .mdb , accdb database
body: <p>I want to connect different access database (they have same tables, same columns) to my system to make a report and this database has a password. I use a <code>openfileDialog</code> to take this database from my files and I want to connect both <code>.mdb</code>, <code>.accdb</code> but but when I use Microsoft.jet.oledb.12.0, I get an error </p>
  
  <blockquote>
    <p>The microsoft.jet.olebd.12.0 provider is not registered on local machine</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code> private void tileBrowse_Click(object sender, EventArgs e)
   {
          OpenFileDialog fdlg = new OpenFileDialog();
          fdlg.Title = "C# Corner Open file Dialog";
          fdlg.InitialDirectory = @"C:\Desktop";
          fdlg.Filter = "(*.mdb)|*.mdb|(*.accdb)|*accdb";
          //fdlg.Filter = "All Files (*.*)|*.mdb|*.accdb" + "MS-Access Database Files (*.accdb)|*.accdb, (*.mdb)|*.mdb";
  
          if (fdlg.ShowDialog() == DialogResult.OK)
          {
              txtFilePath.Text = fdlg.FileName;
          }
   }
  
   private void txtRead_Click(object sender, EventArgs e)
   {
       //connection string 
       String strDSN = "Provider=Microsoft.Jet.OLEDB.12.0;" + "Data Source=" + txtFilePath.Text; 
  
       try
       {
              //Create a connection and open it 
              OleDbConnection conn = new OleDbConnection(strDSN);
              conn.Open();
  
              String strSQl = "SELECT * FROM Student;";
  
              //create data adapter
              OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQl, conn);
  
              // Create and fill dataset
              DataSet dtSet = new DataSet();
              myCmd.Fill(dtSet);
              DataTable dt = dtSet.Tables[0];
              dataGridView1.DataSource = dtSet.Tables[0];
  
              //add items to the list box
              listBox1.Items.Add("ID,F_Name,S_Name," + "Age");
              listBox1.Items.Add("=====================================");
  
              foreach (DataColumn dc in dt.Columns)
              {
                  listBox1.Items.Add(dc.ColumnName + "," + dc.DataType + "," + dc.Unique + "," + dc.AutoIncrement + "," + dc.AllowDBNull);
              }
  
              OleDbCommand cmd = new OleDbCommand("SELECT student.ID, student.F_name, student.S_name, student.Age, Teachers_Info.Teachers_ID, Teachers_Info.Firstname, Teachers_Info.Surname, Teachers_Info.Teachers_Subject, Teachers_Info.Teachers_code FROM student, Teachers_Info ORDER BY student.ID;", conn);
              OleDbDataReader Reader = cmd.ExecuteReader();
  
              //if (Reader.HasRows)
              if (Reader.HasRows)
              {
                  Reader.Read();
                  txtID.Text = (Reader["ID"].ToString());
                  txtF_name.Text = (Reader["F_name"].ToString());
                  txtS_name.Text = (Reader["S_name"].ToString());
                  txtAge.Text = (Reader["Age"].ToString());
  
                  txtTeachers_ID.Text = (Reader["Teachers_ID"].ToString());
                  txtFirstname.Text = (Reader["Firstname"].ToString());
                  txtSurname.Text = (Reader["Surname"].ToString());
                  txtTeachers_Subject.Text = (Reader["Teachers_Subject"].ToString());
                  txtTeachers_code.Text = (Reader["Teachers_code"].ToString());
              }
  
              //close connection
              conn.Close();
          }
          catch (Exception exp)
          {
              MessageBox.Show(exp.Message.ToString());
          }
  }
  </code></pre>