Thursday, January 28, 2010

Passing data from one database to another database table (Access) (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 [Master] SELECT * FROM [MS Access;DATABASE="+
"\\Data.mdb" + ";].[Master]";

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

No comments: