鉴于Excel和Access在某种程度上是兼容的,有没有办法以编程方式将数据从excel文件导入Access数据库,而无需读取文件和插入数据,按记录进行记录?
答案 0 :(得分:4)
非常粗略:
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();