有沒有辦法直接上傳Excel文件並將其內容保存到Sql Server?如何讀取上傳的Excel文件並將其直接保存到數據庫?
謝謝!!
EDITED:
我不想將其保存爲二進制文件。我想讀取它的競爭並將它們保存到數據庫,每個Excel列的內容到數據庫表列等等...
有沒有辦法直接上傳Excel文件並將其內容保存到Sql Server?如何讀取上傳的Excel文件並將其直接保存到數據庫?
謝謝!!
EDITED:
我不想將其保存爲二進制文件。我想讀取它的競爭並將它們保存到數據庫,每個Excel列的內容到數據庫表列等等...
你可以使用這樣的東西..你需要在你的服務器上有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");
我正在使用LintToSql – AndreMiranda 2009-10-23 17:46:03
我知道或產品叫做QueryCell,它允許您使用SQL訪問excell文件。不完全是你在找什麼,但我認爲這是提及。
你可以做一個DTSX包在SSIS將處理Excel文件作爲數據源 - 指定SQL數據庫作爲數據目的地和你離開!
你的意思是文件作爲二進制對象存儲在像圖像/二進制領域? ..這樣你可以讓用戶在以後從數據庫下載它? – 2009-10-23 17:42:43