1
votes

I am new in creating application in Visual Studio 2010. I recently created an application which has a MySQL as a database. Now, I am creating an app where I used a MS Access 2007 as a database.

I have this code for the database connection of MySQL:

class DBConn
{
    string MyConString = "SERVER=localhost;" + "DATABASE=payroll;" + "UID=root;" + "PASSWORD=admin;";
    public DataTable retrieveRecord(string cmd)
    {
        MySqlConnection con = new MySqlConnection(MyConString);
        MySqlCommand command = new MySqlCommand(cmd, con);
        MySqlDataAdapter adp = new MySqlDataAdapter(command);
        con.Open();
        DataSet set = new DataSet();
        adp.Fill(set);
        con.Close();
        return set.Tables[0];
    }
}

My problem now is that how to change this code to access the database of MS Access 2007? Please help. Thanks.

1

1 Answers

3
votes

Change the connection string to something like this: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\yourdatabase.mdb;User Id=username;Password=password;"