使用数据库构建c ++ windows窗体应用程序 [英] Building a c++ windows form application with database

查看:110
本文介绍了使用数据库构建c ++ windows窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的环境

Windows 7(64位)

Visual Studio 2005

MS Access 2010(64位)



我必须创建一个连接到MS访问数据库并交换数据的简单表单应用程序。我正在努力建立连接,并在网上探索了很多资源。

这是我正在使用的代码:



Here is the environment that I have
Windows 7 (64 bit)
Visual Studio 2005
MS Access 2010 (64 bit)

I have to create a simple form application that connects to an MS access database and exchange data. I am struggling to establish the connection and have explored many resources online.
Here is the code that I am using:

System::String^ connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Astute Database\db_retailpro.accdb;Persist Security Info=False;";

System::Data::OleDb::OleDbConnection^ connection = gcnew System::Data::OleDb::OleDbConnection(connectionString);

try
{
    connection->Open();
    Console::WriteLine("DataSource: {0} \nDatabase: {1}", connection->DataSource, connection->Database);
}
catch (Exception^ ex)
{
    Console::WriteLine(ex->Message);
}





抛出以下异常:

类型'的第一次机会异常' System.Data.dll中发生System.InvalidOperationException



有人请告知可能是什么问题?



关于此的更新。现在我发现catch块中的消息显示'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册。

现在怎么办?



This is throwing the following exception:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll

Somebody please advise what could be the problem?

An update on this. Now I have found that the message in the catch block says "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."
What now?

推荐答案

您必须安装MS DAC http: //www.microsoft.com/en-us/download/details.aspx?id=5793 [ ^ ]
You have to install the MS DAC http://www.microsoft.com/en-us/download/details.aspx?id=5793[^]


最后解决了这个问题。这是帮助我的链接。





HTTP? //social.msdn.microsoft.com/Forums/en-US/1d5c04c7-157f-4955-a14b-41d912d50a64/how-to-fix-error-the-microsoftaceoledb120-provider-is-not-registered-on-the- local-machine?forum = vstsdb [ ^ ]



我还在转义序列的数据源位置添加了另一个斜杠。
Finally solved the issue. This is the link that helped me.


http://social.msdn.microsoft.com/Forums/en-US/1d5c04c7-157f-4955-a14b-41d912d50a64/how-to-fix-error-the-microsoftaceoledb120-provider-is-not-registered-on-the-local-machine?forum=vstsdb[^]

Also I added another slash in the data source location for the escape sequence.


这篇关于使用数据库构建c ++ windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆