1
我有Excel 2007和Visual Web Developer Express 2010. 我想导入xlsx文件的Sheet1,阅读器然后将数据添加到数据集并将数据放入MS SQL数据库。将Excel工作表导入MS SQL数据库
string ExcelConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";
string SQLConStr = "got connection string that works";
OleDbConnection ExcelConnection = new OleDbConnection(ExcelConStr);
using (ExcelConnection)
{
string sql = string.Format("Select * FROM [{0}]", "Sheet1$");
OleDbCommand command = new OleDbCommand(sql, ExcelConnection);
ExcelConnection.Open();
using (OleDbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(SQLConStr))
{
bulkCopy.DestinationTableName = "dbo.databaseName";
bulkCopy.WriteToServer(dr);
}
}
}
我需要像bulkcopy这样的东西,如果有人可以提出建议,它是免费且易于使用的。