Please, check:
1) what is returned by
dialog.FileName
. It should be the full filename of another database.
2) does version of both databases are equal? If not, connection string might be differ.
[EDIT]
I have done it in this way and it works perfect:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.Data.OleDb.OleDbConnection oConn = null; System.Data.OleDb.OleDbCommand oComm = null;
string sConn = String.Empty; System.Text.StringBuilder sComm = null ;
string sDb1 = String.Empty; string sDb2 = String.Empty;
int retVal = 0;
try
{
sDb1 = "C:\\db1.mdb";
sDb2 = "C:\\db2.mdb";
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDb2 + ";";
oConn = new System.Data.OleDb.OleDbConnection(sConn);
oConn.Open();
sComm = new StringBuilder();
sComm.AppendLine("INSERT INTO tblUsers (ID, UserName)");
sComm.AppendLine("SELECT *");
sComm.AppendLine("FROM tblUsers IN '" + sDb1 + "'");
sComm.AppendLine("WHERE ID = 1;");
Console.WriteLine(sComm.ToString());
oComm = new System.Data.OleDb.OleDbCommand(sComm.ToString(), oConn);
retVal = oComm.ExecuteNonQuery();
Console.WriteLine("Records affected: {0}", retVal.ToString());
}
catch (System.Data.OleDb.OleDbException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (oConn.State == System.Data.ConnectionState.Open ) oConn.Close();
Console.ReadKey();
}
}
}
}
Text displayed in Console:
INSERT INTO tblUsers (ID, UserName)
SELECT *
FROM tblUsers IN 'C:\db1.mdb'
WHERE ID = 1;
Records affected: 1
Check connection string to your database and add
try..catch[
^] block.
http://www.connectionstrings.com/access-2007[
^]
[/EDIT]