如何打开和写入Access数据库 [英] How to open and write to Access database

查看:96
本文介绍了如何打开和写入Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我只是想在本地计算机上打开一个Access数据库,并向其中写入一些数据.我似乎什么也没工作.

这是我尝试过的示例:

Hi,
I''m just trying to open an Access database on my local machine and write some data to it. I cannot seem to get anything to work.

Here''s an example of something I''ve tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            {
            //create the database connection
            OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\P\\Documents\\Practice Access Files");

            //create the command object and store the sql query
            OleDbCommand aCommand = new OleDbCommand("select * from emp_test", aConnection);
            try
            {
                aConnection.Open();
                aConnection.Close();
            }
            catch (OleDbException e)
            {
                Console.WriteLine("Error: {0}", e.Errors[0].Message);
            }

            
            }


        }
    }
}
</pre>

Here I''m just trying to open and close the connection. 
For this I receive this message:

<code>"The ''Microsoft.Jet.OLEDB.4.0'' provider is not registered on the local machine."</code>


I''ve looked this error up and found it has something to do with the fact that I''m running 64-bit Windows. I registered the database via command prompt as per instructions at the MS website but it still gives the same message. 

I should stress that I am by no means committed to Jet OLE DB, it''s just the most accessible code example I could find.

I''m really looking for any means to open and write to a database stored on my local machine.

Thanks,
Jeff

推荐答案

您好,

尽管网上有指南解释如何在64位操作系统下安装32位驱动程序,但我认为最好的方法是为x86构建应用程序.这样,您不必担心为客户端安装执行相同的繁琐操作.

我猜想您现在已经将Visual Studio设置为任何CPU",只需进入配置管理器"(您可以通过选择任何CPU"的下拉列表中找到它).然后,从左侧下拉列表中选择新建",然后从上方列表中选择"x86".将复制设置自"保留为任何CPU",然后按OK.再次按OK,您应该看到它现在显示的是"x86",而不是"Any CPU".尝试重建并运行您的应用程序,它现在应该使用32位驱动程序,并且只要安装了它们就可以自动找到它们.

/Geir Rune
Hi there,

Although there are guides on the web explaining how to install the 32bit drivers under 64bit OS, I think the best way forward would be to build your application for x86. This way you won''t have to worry about performing the same tedious operation for the client installs.

I''m guessing that you have Visual Studio set to to "Any CPU" at the moment, just go into the "Configuration Manager" (you can reach it through the drop-down where Any CPU is selected). Then, from the left hand drop down, select "New" and select "x86" from the upper list. Leave the "Copy settings from" to "Any cpu" and press OK. Press OK again and you should see that instead of "Any CPU" it now says "x86". Try to rebuild and run your application, it should now use the 32bit drivers and find them automatically as long as you have them installed.

/Geir Rune


盖尔,

您所描述的确实可以正常工作.这有点棘手,因为我正在使用Express,但找不到配置管理器.但是经过一番研究,我发现了它并将其更改为x86.

谢谢,
杰夫
Hi Geir,

What you described does work properly. It was a little tricky because I''m using Express and couldn''t find the Configuration Manager. But with a little research I found it and made the change to x86.

Thanks,
Jeff


这篇关于如何打开和写入Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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