Purpose: To import data from excel to ms access (.mdb) database.
Reference: https://www.mikesdotnetting.com/article/79/import-data-from-excel-to-access-with-asp-net
Technology: C#.net Windows Forms
Error: "The Microsoft Jet database engine cannot find the input table or query 'Persons$'. Make sure it exists and that its name is spelled correctly."
Code:
private void button6_Click(object sender, EventArgs e)
{
string Access = @"c:\exportdb\DestinationDB.mdb";
string connect = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\exportdb\DestinationDB.mdb;";
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO [MS Access;Database=" + Access + "].[Persons] SELECT * FROM [Persons$]";
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
Note: I have created a MS Access database named "DestinationDB.mdb" with table name as "Persons" with the following fields: ContactID, FirstName, SecondName, Age
Thereafter i have exported the same to excel in order to retain the header structure.
Once this excel is exported, i added some 10 records to it manually.
Both the files are located under "c://exportdb/source.xls" & "c://exportdb/DestinationDB.mdb".
Please help me to resolve the error stated above.
Thanks!

