有没有办法上传Excel文件并直接将其内容保存到Sql Server?
谢谢!
EDITED :
我不想将其保存为二进制文件。我想阅读它的争议并将它们保存到DB,将每个Excel列内容保存到DB表列中,依此类推......
答案 0 :(得分:1)
我知道或者名为QueryCell的产品允许您使用SQL访问excell文件。不完全是你想要的,但我认为这是提到的。
答案 1 :(得分:1)
您可以使用类似的东西..您需要在服务器上安装oledb驱动器。
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + uploadFilenm + "; Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34;
// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);
// Open connection with the database.
objConn.Open();
// The code to follow uses a SQL SELECT command to display the data from the worksheet.
// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [sheet1$]", objConn);
// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;
// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();
// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");
答案 2 :(得分:0)
您可以在SSIS中创建一个dtsx包,将excel文件视为数据源 - 将您的SQL数据库指定为数据目的地,然后您就离开了!