Update Excel Database Records
Converting Excel WorkBook.ToDataSet()
allows .NET developers to first manipulate the dataset, and then use it to update SQL records very easily using System.Data
.
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
Converting Excel WorkBook.ToDataSet()
allows .NET developers to first manipulate the dataset, and then use it to update SQL records very easily using System.Data
.
9 .NET API products for your office documents