How to Import and Export as DataSet

by Chaknith Bin

A DataSet is an in-memory representation of data that can hold multiple related tables, relationships, and constraints. It's often used for working with data from various sources like databases, XML, and more.

A DataTable is a fundamental building block within a DataSet. It represents a single table with rows and columns, much like a table in a database. It's used to organize and manipulate data in a tabular form.

You can import a DataSet into a spreadsheet object and export it back into a DataSet using IronXL.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Load DataSet

Utilize the static LoadWorkSheetsFromDataSet method of the WorkBook to import a DataSet into the workbook. This method requires both the DataSet and WorkBook objects. Consequently, you should initiate the workbook or spreadsheet beforehand using the Create method. In the provided code example, provide the DataSet object you wish to convert to the method, alongside the workbook object.

:path=/static-assets/excel/content-code-examples/how-to/export-dataset-datatable-load.cs
using IronXL;
using System.Data;

// Create dataset
DataSet dataSet = new DataSet();

// Create workbook
WorkBook workBook = WorkBook.Create();

// Load DataSet to workBook
WorkBook.LoadWorkSheetsFromDataSet(dataSet, workBook);
Imports IronXL
Imports System.Data

' Create dataset
Private dataSet As New DataSet()

' Create workbook
Private workBook As WorkBook = WorkBook.Create()

' Load DataSet to workBook
WorkBook.LoadWorkSheetsFromDataSet(dataSet, workBook)
VB   C#

Visit the How to Load Existing Spreadsheets article to learn more about importing spreadsheet from various file formats.


Export DataSet

The ToDataSet method converts the workbook to a System.Data.DataSet, where each worksheet represents a System.Data.DataTable. Use this method on the current Excel workbook to convert it from a workbook to a DataSet object. The useFirstRowAsColumnNames parameter of the method configures whether to use the first row as column names.

:path=/static-assets/excel/content-code-examples/how-to/export-dataset-datatable-export.cs
using IronXL;
using System.Data;

// Create new Excel WorkBook document
WorkBook workBook = WorkBook.Create();

// Create a blank WorkSheet
WorkSheet workSheet = workBook.CreateWorkSheet("new_sheet");

// Export as DataSet
DataSet dataSet = workBook.ToDataSet();
Imports IronXL
Imports System.Data

' Create new Excel WorkBook document
Private workBook As WorkBook = WorkBook.Create()

' Create a blank WorkSheet
Private workSheet As WorkSheet = workBook.CreateWorkSheet("new_sheet")

' Export as DataSet
Private dataSet As DataSet = workBook.ToDataSet()
VB   C#

Visit the How to Save or Export Spreadsheets article to learn more about exporting spreadsheet to various file formats.

Chaknith related to Export DataSet

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.