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
Actualizar registros de bases de datos Excel
Conversión de Excel WorkBook.ToDataSet()permite a los desarrolladores .NET manipular primero el conjunto de datos y, a continuación, utilizarlo para actualizar registros SQL de forma muy sencilla medianteSystem.Data`.
Enlaces a documentos relacionados
¿Listo para empezar? Versión: 2024.11 acaba de salir