我正在尝试将数据从一个MS Access数据库导入到另一个MS Access数据库,并且发现以下工作正常,我遇到的问题是,如果从数据库锁定了SYSTEM,是否有人知道我应该使用什么。 MDW
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Data\Database1.mdb;User Id=admin;Password=;";
string commandText = "INSERT INTO [TableName] SELECT * FROM [MS Access;DATABASE=C:\\Data\Database2.mdb].[TableName]";
try
{
using (OleDbConnection oleConnection = new OleDbConnection(connectionString))
{
using (OleDbCommand oleCommand = new OleDbCommand(commandText, oleConnection))
{
oleCommand.CommandType = CommandType.Text;
oleCommand.Connection.Open();
oleCommand.ExecuteNonQuery();
}
}
}
catch (Exception)
{
throw;
}
我可以使用Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Database2.MDB;System Database=C:\Data\SYSTEM.MDW;User ID=Developer;Password=Password
答案 0 :(得分:0)
如果您可以打开 From 数据库,请打开它并从中执行操作:
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Database2.MDB;System Database=C:\Data\SYSTEM.MDW;User ID=Developer;Password=Password";
string commandText = "INSERT INTO [TableName] In 'C:\\Data\Database1.mdb' SELECT * FROM [TableName]";
try
{
using (OleDbConnection oleConnection = new OleDbConnection(connectionString))
{
using (OleDbCommand oleCommand = new OleDbCommand(commandText, oleConnection))
{
oleCommand.CommandType = CommandType.Text;
oleCommand.Connection.Open();
oleCommand.ExecuteNonQuery();
}
}
}
catch (Exception)
{
throw;
}