IronSoftware
  • Products
    Create, read, and edit PDFs Image to text in 127 languages Read and write QR & Barcodes No Office Interop required Extract structured data from websites 5 for the Price of 2 All 5 .NET product licenses from $998 Save 60% with Iron Suite Iron Suites - Donate $50
  • About Us
  • Contact Us
  • Home
  • Licensing
  • EULA
  • Support & Update Extensions
  • Get Started
  • Features
  • Code Examples
  • Tutorials
  • FAQ
  • Troubleshooting
  • API Reference
  • Search
  • Free NuGet Download
IronXL - Excel Library for C# .Net IronXL - Excel Library for C# .Net
  • Home
  • Licensing
    • Licensing
    • EULA
    • Support & Update Extensions
  • Docs
    • Search
    • Get Started
    • Features
    • Code Examples
    • Tutorials
    • FAQ
    • Troubleshooting
    • API Reference
    • Search
  • Search
  • Free NuGet Download Total downloads: 154,527
Message's icon
IronXL
Code Examples
  1. IronXL
  2. Code Examples
  3. Excel to DataSet and Back Again in C#
IronXL
Free for development from NuGet

Install with NuGet nuget.org/packages/IronXL.Excel

PM > Install-Package IronXL.Excel

Explore the Docs

  • Get Started
  • Features
  • Code Examples
    • How to Read an Excel File in C#
    • Using C# to Create Excel Files in .Net
    • Use C# to Open & Write an Excel File
    • License Keys
    • Create an XLSX File
    • Work with Excel in .NET Core
    • Export to Excel in C#
    • Read XLSX File C#
    • Work with Excel in C# without Interop
    • Write Excel Values in .NET
    • Open Excel Worksheets in C#
    • Parse Excel Files in C#
    • Read Excel File Example
    • Work with VB .NET Excel Files
    • Add Rows & Columns in Excel C# Docs
    • Import Excel Data in C#
    • Generate Excel Files in C#
    • Create Excel Documents in C#
    • Edit Excel Files in C#
    • Merge Cells in Excel C# Documents
    • Create Excel Charts in C#
    • Read a CSV in C#
    • Write CSV in .NET
    • Use a CSV parser in C#
    • Create a CSV file using C#
    • Convert a Data Table to CSV
    • Convert XLSX to CSV, JSON, XML
    • macOS Compatibility
    • AWS Lambada Support
    • Azure & Azure Function Setup
    • Docker Setup Guide
    • Linux Compatibility & Config
    • Troubleshooting Guides
      • Apply a license key in IronXL
      • File Size Limits
    • Product Release Notes
      • IronXL v2021.11.0
      • IronXL v2021.12.0
      • IronXL v2022.3.0
  • API Reference
Read Excel Files without Interop
Excel Worksheets
Excel Range Cells
Create a new Excel File
Convert Spreadsheet File Types
Excel to SQL via System.Data.DataSet
Excel to SQL and DataGrid via DataTable
Excel Conditional Formatting
Convert XLS to XLSX in C#
Protect Excel Files
Excel Formulas in C#
Save Excel to Database
Edit Excel Metadata in C#
Update Excel Database Records
Style Excel Cell Borders & Fonts
Sort Excel Ranges in C#
Repeat Excel Rows & Columns
Read XLSX Files
Excel Print Setup
Preserve Excel Macros in XLSM
Excel Number Format
Load Excel From SQL Database
Combine Excel Ranges
Select Excel Range
Generate Excel Files
XLSX to XLSM with Macros
Convert Excel to XLSM
Convert Excel to HTML
Import Export Excel
Aggregate Excel Functions
CSV to Excel
Create Excel Scatter Chart
Create Excel Line Chart
Create Excel Bar Chart
Freeze Panes in Excel
Create Excel Worksheet
Copy Excel Worksheets

Excel to SQL via System.Data.DataSet

using IronXL;
using System.Data;

 //Open any Excel document.
WorkBook workbook = WorkBook.Load("test.xls");

// Convert the whole Excel WorkBook to a DataSet
// This allows us to work with DataGrids and System.Data.SQL nicely
var dataSet = workbook.ToDataSet();
foreach (DataTable table in dataSet.Tables)
{
    Console.WriteLine(table.TableName);

     //Enumerate by rows or columns first at your preference
	foreach (DataRow row in table.Rows)
	{
	    for (int i = 0; i < table.Columns.Count; i++)
	    {
	        Console.Write(row[i]);
	    }
	}
}
Imports IronXL
Imports System.Data

 'Open any Excel document.
Private workbook As WorkBook = WorkBook.Load("test.xls")

' Convert the whole Excel WorkBook to a DataSet
' This allows us to work with DataGrids and System.Data.SQL nicely
Private dataSet = workbook.ToDataSet()
For Each table As DataTable In dataSet.Tables
	Console.WriteLine(table.TableName)

	 'Enumerate by rows or columns first at your preference
	For Each row As DataRow In table.Rows
		For i As Integer = 0 To table.Columns.Count - 1
			Console.Write(row(i))
		Next i
	Next row
Next table
Read more
Try IronXL free for development
Download Free Free Nuget Download
Install-Package IronXL.Excel

Excel to SQL via System.Data.DataSet

Convert any XLS or XLSX Excel file (WorkBook) to a System.Data.DataTable for full interoperability with System.Data.SQL or to populate a DataGrid.
Previous Example
Next Example

Ready to get started? Version: 2022.3.0 just released

Free NuGet Download Total downloads: 154,527 View Licenses >
Try IronXL for Free
Get Set Up in 5 Minutes
C# Nuget Library for PDF
Install with NuGet
Version: 2022.3.0
Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL
Version: 2022.3.0
Download Now
Manually install into your project
  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"
Licenses from $499

Have a question? Get in touch with our development team.

Now that you’ve downloaded IronXL
Want to deploy IronXL to a live project for FREE?
What’s included?
30 days of fully-functional product
Test and share in a live environment
No restrictions in production
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Thank you.
View your license options:
View License
Have a question? Get in touch with our development team.
Want to deploy IronXL to a live project for FREE?
What’s included?
30 days of fully-functional product
Test and share in a live environment
No restrictions in production
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Download IronXL free to apply
your Trial Licenses Key
Install with NuGet View Licenses
Licenses from $499. Have a question? Get in touch.
Free 30-Day Trial Key
IronXL for .NET

The Excel API you need, without the Office Interop hassle.

Search

Documentation

  • Code Examples
  • API Reference
  • FAQ
  • Features
  • Blog
  • Credits
  • Product Brochure

Tutorials

  • Get Started
  • Read an Excel File in C#
  • Create Excel Files in .Net

Licensing

  • Buy a License
  • Support Extensions
  • Resellers
  • License Keys
  • EULA

Try IronXL Free

  • Download on NuGet
  • Download DLL
  • 30-Day Trial License

When you need your PDF to look like HTML, fast.

Tesseract 5 OCR in the languages you need, We support 127+.

When you need to read, write, and style, QR & Barcodes, fast.

The Excel API you need, without the Office Interop hassle.

The power you need to scrape & output clean, structured data.

The complete .NET Suite for your office.

  • IRONSUITE
  • |
  • IRONPDF
  • IRONOCR
  • IRONBARCODE
  • IRONXL
  • IRONWEBSCRAPER
IronSoftware
205 N. Michigan Ave. Chicago, IL 60611 USA +1 (312) 500-3060
  • About Us
  • Contact Us

Supporting Teamseas

Copyright © Iron Software LLC 2013-2022

  • Terms
  • Privacy

Thank you!

Your license key has been delivered to the email provided. Contact us

48-Hour Upgrade Offer:

Save 50% on a
Professional Upgrade

Go Professional to cover 10 developers
and unlimited projects.

Upgrade to Professional

Upgrade

Professional

$600 USD

$299 USD


  • 10 developers
  • 10 locations
  • 10 projects