使用C#和MS Access Oledb在Windows Forms中将表从一个数据库复制到另一个数据库 [英] Copy table from one database to another in Windows Forms using C# and MS Access Oledb

查看:459
本文介绍了使用C#和MS Access Oledb在Windows Forms中将表从一个数据库复制到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将表从一个数据库复制到另一个数据库,我正在使用c#在.NET中开发一个Windows应用程序。复制必须由应用程序完成。从数据库1中的填充表中将数据提取到数据库2中的空表中。我使用访问db,Oledbconnection。我发现一些答案sql服务器虽然,但不是真的帮助。

How to copy a table from one database to another , I'm developing a windows app using c# in .NET.The copying has to be done by the app. Extract data into an empty table in database 2 from a filled table in database1.I'm using access db , Oledbconnection. I found some answers for sql server though , but not really helping.

推荐答案

您可以参考SQL中的第二个DB,并针对与第一个mdb / accdb的连接执行:

You can refer to the second DB in SQL and execute against a connection to the first mdb/accdb:

使用System.Data.OleDb连接

Connection

using System.Data.OleDb;
<...>
string ConnString =
     @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Docs\first.accdb";
OleDbConnection conn = new OleDbConnection(ConnString);

SQL

INSERT INTO Contacts ( ID, [A Text] ) IN 'z:\docs\New.accdb'
SELECT Contacts.ID, Contacts.[A Text]
FROM Contacts;

INSERT INTO [;DATABASE=Z:\Docs\new.accdb].Contacts ( ID, [A Text] )
SELECT Contacts.ID, Contacts.[A Text]
FROM Contacts;

或创建表格:

SELECT Contacts.ID, Contacts.[A Text] INTO Contacts IN 'z:\docs\New.accdb'
FROM Contacts;

这篇关于使用C#和MS Access Oledb在Windows Forms中将表从一个数据库复制到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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