更新 Excel 資料庫記錄 IronXL的 ToDataSet 方法可讓開發人員以最少的努力直接從 Excel 資料同步並更新 SQL 資料庫記錄。 此功能透過將 Excel 工作簿轉換為 DataSet,實現表格 Excel 資料與關聯式資料庫之間的無縫整合。 它無需手動輸入資料或進行複雜的轉換,這大大簡化了資料管理工作流程。 此功能對於需要定期從外部 Excel 檔案更新資料庫記錄的應用程式(例如客戶資料、財務記錄或庫存管理系統)尤其有用。 與 SQL 查詢和適配器的相容性使開發人員能夠將 Excel 資料對應到現有的資料庫架構。 IronXL支援多種 Excel 格式(XLSX、CSV 等),確保在各種使用情境中的通用性。 此功能利用 SqlDataAdapter 進行大量更新,從而減少資料處理時間,最大限度地減少錯誤,並確保 Excel 和資料庫記錄之間的一致性,使其成為企業級應用程式的理想解決方案。 ## 五個步驟教你如何將 Excel 資料更新到 SQL 資料庫 `var workBook = WorkBook.Load("Products.xlsx");` `DataSet dataSet = workBook.ToDataSet();` `string sql = "SELECT * FROM products";` `using var adapter = new SqlDataAdapter(sql, new SqlConnection("Your Connection String"));` `new SqlCommandBuilder(adapter).DataAdapter.Update(dataSet);` 此程式碼示範如何使用IronXL和.NET將 Excel 檔案中的資料更新到 SQL 資料庫的過程。 The WorkBook.Load method loads the Excel file named Products.xlsx into memory, and the ToDataSet method converts the workbook into a DataSet, which organizes the data into a tabular structure compatible with ADO.NET. A SQL query is defined to interact with a specific table in the database (products). The SqlDataAdapter is initialized with the query and a connection string, enabling it to act as a bridge between the DataSet and the database. The SqlCommandBuilder is used to automatically generate the necessary SQL commands for inserting, updating, or deleting data in the database. Finally, the adapter.Update(dataSet) method synchronizes the changes in the DataSet (populated from the Excel file) with the corresponding database table. 這樣可以簡化資料傳輸過程,並確保資料庫反映 Excel 文件中的最新變更。 了解如何使用IronXL將資料集匯出至 Excel 相關文檔連結 在 Github 上查看 相關教程 相關操作指南 類文檔 下載 IronXL DLL 回報此頁面的問題 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 12 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 19 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 準備好開始了嗎? Nuget 下載 1,890,100 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:1,890,100 查看許可證 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 17 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/examples/index.php Line: 270 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 24 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/examples/index.php Line: 270 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Examples.php Line: 44 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 還在捲動嗎? 想要快速證明? PM > Install-Package IronXl.Excel 執行範例 觀看您的資料變成試算表。 免費 NuGet 下載 總下載量:1,890,100 查看許可證