apomene
apomene

Reputation: 14389

Mass Import Data from Excel file to Access programmatically in C#

Given the fact that Excel and Access are compatible in some level, is there a way to import data from an excel file to an Access Database programmatically, without reading the file and inserting data, record by record?

Upvotes: 1

Views: 5792

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

Very roughly:

string ConnString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Docs\Test.accdb";
OleDbConnection conn = new OleDbConnection(ConnString);
conn.Open();
string sql = @"select * into newxl from [Excel 8.0;HDR=YES;DATABASE=Z:\Docs\Test.xlsx].[Sheet1$] s;";

OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.ExecuteNonQuery();

Upvotes: 5

Related Questions