string path = string.Concat(Server.MapPath("~/TempFiles/"), FileUpload1.FileName);
//Save File as Temp then you can delete it if you want
FileUpload1.SaveAs(path);
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
// Create Connection to Excel Workbook
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
("Select * FROM [Sheet1$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = @conn;
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName ="Table1";
bulkCopy.WriteToServer(dr);
Label1.Text = "The Client data has been exported successfully from Excel to SQL";
}
}
}
我試圖從Excel到SQL Server導入數據,它工作得很好,直到我沒有通過的日期,但現在我想傳遞的日期到SQL Server提供由於數據類型不匹配而導致錯誤。導入數據從Excel到SQL Server 2008#2
任何人有邏輯或請建議我,我能做些什麼來..
我怎麼能轉換它,因爲我導入數據在BU lk .. 是否有任何東西可以導入到數據表中,然後導入到sql服務器,以便我們可以檢查數據表中的每個數據並將其轉換爲 – user2919184
檢查我的更新答案。 – Adil
你好,因爲我是新來的asp我不知道,但我檢查了..我使用datareader nd我正在執行datareader插入我的價值,如果我寫入數據表,然後如何執行它的數據值插入我的數據? ? n thanx爲您的回覆 – user2919184