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.
将连接字符串更改为如下所示:“Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\ yourdatabase.mdb; User Id = username; Password = password;”
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.