好吧,我已经做了-我能够通过Microsoft.Jet.OLEDB提供者连接到access mdb表,然后我可以使用select query,OleDbDataAdapter和DataSet从表中获取数据。
现在,我可以通过Npgsql连接到Postgresql,但是我不知道如何从access表中获取数据并将其放入postgresql表中?
我想完成的-是从access mdb表中获取数据,并使用"select into“查询将其插入到postgresql表中。
发布于 2010-07-06 19:39:12
在这种情况下,我不认为您能够使用从一个数据库到另一个数据库的"SELECT INTO“查询(因为这两个数据库位于不同的引擎上)。您需要做的是存储数据,从MDB中将数据读取到某个CLR对象中,然后将CLR数据读取到PostgreSQL数据库中,这相当简单。只是不可能按你想要的方式去做
发布于 2010-07-07 00:36:11
这里有一些非常业余的笔记,可能会对你有所帮助。它们引用SQL Server Express,因为我没有访问postgressql的权限。我通过将SQL server表链接到Access并检查连接属性获得了连接字符串,但是,您也可以查看此处:http://www.connectionstrings.com/postgre-sql。这两行将值从Access中的table1插入到SQL Express中的table2中。在Access中,如果查询不正确,则查询将失败,并且不会出现警告(本例中为Access 2010 )。我在Visual c# 2010学习版中尝试了这一点。
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\docs\\db.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("INSERT into [ODBC;Description=TEST;DRIVER=SQL Server;SERVER=COMP\\SQLEXPRESS;Trusted_Connection=Yes;DATABASE=test].Table2 (id, atext) select id, atext from table1", aConnection);发布于 2010-07-12 17:36:34
嘿,感谢所有帮助过我的人,我终于明白了。因此,对于所有将遇到相同情况的人-以下是为Postgresql提供正确连接字符串的解决方案:
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\docs\\db.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("INSERT into [ODBC;DSN=PostgreSQL;DATABASE=postgres;SERVER=localhost;PORT=5432;UID=postgres;PWD=test;].Table2 (id, atext) select id, atext from table1", aConnection);https://stackoverflow.com/questions/3185793
复制相似问题