我想为一个练习做一个简单的应用程序,所以连接到像Access这样的简单数据库(.accdb)会很不错
我的程序看起来像这样:
using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Linq; using System.Web; namespace myProject.Account { public class DbManager { private OleDbConnection _dbConnection; public void OpenDbConnection() { _dbConnection = new OleDbConnection {ConnectionString = GetConnectionString()}; } private string GetConnectionString() { return "Provider=Microsoft.ACE.OLEDB.14.0;Data Source=exercise1.accdb"; } public void CloseDbConnection() { _dbConnection.Close(); } public void GetUser() { DataSet myDataSet = new DataSet(); var myAdapptor = new OleDbDataAdapter(); OleDbCommand command = new OleDbCommand("SELECT * FROM tblUser", _dbConnection); myAdapptor.SelectCommand = command; myAdapptor.Fill(myDataSet, "tblUser"); } } }
我使用Visual Studio 2010.当我使用内置调试模式"Start without Debugging"(CTRL + F5)测试我的应用程序时,我收到此错误:
"Microsoft.ACE.OLEDB.14.0"提供程序未在本地计算机上注册.
我曾尝试从Microsoft omepage下载并安装"Microsoft Access Database Engine 2010 Redistributable"(64位):http://www.microsoft.com/download/en/details.aspx?id = 13255
不幸的是,它没有解决问题.执行myAdapptor.Fill()时仍然出现错误.怎么了?
您需要Access 2007 Runtime.