2012-09-06 99 views
0

我需要將Excel文件中的數據導入到SQL Server數據庫中。該數據文件包含我需要導入的大約120,000條記錄(行)。 excel文件中的每行數據由大約183個格式化的數據列組成,數據將分散到SQL端的大約13個不同的表中。將所有這些記錄導入到SQL中最好的方式(最簡單但性能最好)是什麼,以確保每行都得到正確處理。如何將Excel文檔數據逐頁導入到SQL表中

另一種方法是有一個選項,將數據加載到數據庫中的臨時數據表中,然後運行腳本將所有數據列從臨時表移動到各種其他表中。

回答

2

我用這種方式來從CSV文件獲取數據: - >

 int f = 0; 
var reader = new StreamReader(File.OpenRead(@ExcelFilePath)); 
       Buisness_logic bl = new Buisness_logic(); 

       while (!reader.EndOfStream) 
       { 
         if (f == 0) 
        { 
         var line = reader.ReadLine(); 
         f++; 
        } 
        else 
        { 
         var line = reader.ReadLine(); 
         string[] s = line.Split(','); 
         count = s.Length; 
         if (s.Length == 3) 
         { 
          var values = line.Split(','); 
          string query = "Insert into Events_party values('" + identity + "','" + values[0] + "','" + values[1] + "','" + values[2] + "','" + time + "','" + dt + "')"; 
          bl.ExecuteQuery(query); 
          count = 101; 
         } 
         else 
         { 
          MessageBox.Show("Imported File was not in defined format !! ", ".File Format Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
          textBox1.BackColor = Color.Pink; 
          break; 
          count = 100; 
         } 
        } 
       } 
+0

進口幾乎120000行時效率如何呢? – Kobojunkie

相關問題