简体   繁体   English

将数据从一个数据库传递到另一数据库表

[英]Passing data from one database to another database table

I want to take a backup of my Access database Pragmatically. 我想以实用的方式备份Access数据库。 And After taking all data in backup i want to delete data from source database. 在将所有数据备份后,我想从源数据库中删除数据。 ( So that it will not take much time while querying and filtering through application.) (这样一来,通过应用程序进行查询和过滤就不会花费很多时间。)

The source database name is Data.mdb The destination database name is Backup.mdb Both are protected by same password. 源数据库名称为Data.mdb,目标数据库名称为Backup.mdb两者均受同一密码保护。

For these purpose i am writing a query in C# like this. 为此,我正在C#中编写这样的查询。

string conString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Backup.mdb;Jet    
                   OLEDB:Database Password=12345";
OleDbConnection dbconn = new OleDbConnection();
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand dbcommand = new OleDbCommand();

try
{
   if (dbconn.State == ConnectionState.Closed)
      dbconn.Open();

 string selQuery = "INSERT INTO [Bill_Master] SELECT * FROM [MS Access;DATABASE="+     
                   "\\Data.mdb" + "; Jet OLEDB:Database Password=12345;].[Bill_Master]";

 dbcommand.CommandText = selQuery;
 dbcommand.CommandType = CommandType.Text;
 dbcommand.Connection = dbconn;
 int result = dbcommand.ExecuteNonQuery();
 }
 catch(Exception ex)   {}

Everything goes fine if i try with without password database file. 如果我尝试不使用密码数据库文件,一切都会很好。 I think error in passing password on query statement. 我认为在查询语句中传递密码时出错。 I am trying to execute through access query but it is saying "Invalid argument". 我正在尝试通过访问查询执行,但是它说的是“无效的参数”。 Please is there any other programing logic for doing that. 请执行其他任何编程逻辑。 Thanks 谢谢

prashant YuvaDeveloper 令人沮丧的YuvaDeveloper

Are Data.mdb and Backup.mdb identically in strcuture? Data.mdb和Backup.mdb的结构是否完全相同? If so, I wouldn't bother copying data via SQL but just copy the whole file. 如果是这样,我不会费心通过SQL复制数据,而只是复制整个文件。

Try remove the space between the ; 尝试删除之间的空间; and Jet … So the format would be: Jet …因此格式为:

INSERT INTO [Bill_Master] SELECT * FROM [MS Access;DATABASE="+     
               "\\Data.mdb" + ";Jet OLEDB:Database Password=12345;].[Bill_Master]

You can copy and rename Data.mdb, and then truncate all the tables in Data.mdb. 您可以复制并重命名Data.mdb,然后截断Data.mdb中的所有表。 Far easier than trying to copy a table at a time.. 比一次尝试复制表格要容易得多。

Don't delete data. 不要删除数据。 This becomes a lot mroe difficult in the future to do analysis or inquiries. 将来进行分析或查询将变得非常困难。 If it's taking a long time then review indexing or upszing to SQL Server. 如果要花费很长时间,请查看索引或升级到SQL Server。 The Express edition is free and can handle databases up to 4 Gb. Express版是免费的,可以处理最大4 Gb的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从一个表复制到另一个数据库中的另一个表 - copy data from one table to another table in another database 每5秒将数据从一个表复制到另一个@mysql数据库 - copy data from one table to another @mysql database every 5 secs 将数据从一个表插入数据库中的另一个表(不同的服务器) - Inserting data from one table to another in a database(different servers) 将数据从一个表移动到同一数据库中的另一个表 - Move data from one table to another in the same Database 如何使用ASP.NET MVC将数据从一个数据库表移动到同一数据库的另一表? - How to move data from one database table to another table of same database using ASP.NET MVC? 将一个数据库表的数据复制到另一个 - Copying the data of one database table to another 数据从一个数据库传输到另一个数据库 - Data transfer from One database to another 如何将数据从一个数据库导入到另一个数据库 - How to import data from one database to another 如何从数据库中的表读取数据并将其插入另一个数据库? - how to read data from a table in database and insert into another database? 使用C#dataAdapter.Fill()和dataAdapter.Update()将表的数据从一个数据库传输到另一个数据库的同一表 - Transfer data of a table from one database, to the same table of another database, using C# dataAdapter.Fill() and dataAdapter.Update()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM