更新Excel数据库记录
转换 Excel `WorkBook.ToDataSet().NET开发人员可以首先操作数据集,然后使用 "System.Data "非常方便地更新SQL记录。
using IronXL; using System.Data; using System.Data.SqlClient; // Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV WorkBook workBook = WorkBook.Load("sample.xlsx"); // Convert the workbook to ToDataSet DataSet dataSet = workBook.ToDataSet(); // Your sql query string sql = "SELECT * FROM Users"; // Your connection string string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=usersdb;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { // Open connections to the database connection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sql, connection); // Update the values in database using the values in Excel adapter.Update(dataSet); }
Imports IronXL Imports System.Data Imports System.Data.SqlClient ' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV Private workBook As WorkBook = WorkBook.Load("sample.xlsx") ' Convert the workbook to ToDataSet Private dataSet As DataSet = workBook.ToDataSet() ' Your sql query Private sql As String = "SELECT * FROM Users" ' Your connection string Private connectionString As String = "Data Source=.\SQLEXPRESS;Initial Catalog=usersdb;Integrated Security=True" Using connection As New SqlConnection(connectionString) ' Open connections to the database connection.Open() Dim adapter As New SqlDataAdapter(sql, connection) ' Update the values in database using the values in Excel adapter.Update(dataSet) End Using
Install-Package IronXL.Excel
转换 Excel `WorkBook.ToDataSet().NET开发人员可以首先操作数据集,然后使用 "System.Data "非常方便地更新SQL记录。