Read and Import Excel File into DataSet
In the earlier examples, we utilized the Microsoft Excel 12.0 Object Library to read from and write to Excel files. However, in C#, it is also possible to perform operations such as inserting, editing, deleting, and selecting cell content in an Excel file without employing the Excel Object. This can be accomplished using the OLEDB (Object Linking and Embedding Database) approach.
OLEDB (Object Linking and Embedding Database)
By using OLEDB, developers can interact with Excel files programmatically, enabling seamless manipulation of cell data within the file. This alternative method provides flexibility and versatility in working with Excel files, presenting an efficient approach to perform various operations without directly relying on the Excel Object.
In order to perform operations such as inserting, editing, deleting, and selecting cell content in an Excel file without relying on the Excel Object, we utilize components such as OleDbConnection, OleDbDataAdapter, and DataSet within the ADO.NET framework. Importing the System.Data namespace into the project is essential for utilizing these components effectively. When reading content from an Excel file using ADO.NET, we can employ the SELECT command, similar to SQL operations, to retrieve the desired data from the Excel file. This approach offers a seamless integration with Excel files, allowing for efficient data manipulation and retrieval without direct dependency on the Excel Object model.
sample Select sql
Here is the sample Excel file .
Open the connection using OLEDB Provider
(provider=Microsoft.Jet.OLEDB.4.0;Data Source='Your Filename';Extended Properties=Excel 8.0;)Specify which data you want to read
Excel to Dataset
Here is the screen short after reading from Excel file in C# .
Full Source C#- How to create Excel file in C#
- How to open an Excel file in C#
- How to read an Excel file using C#
- How to programmatically Add New Worksheets
- How to delete worksheet from an excel file
- How to format an Excel file using C#
- How to insert a picture in excel from C# App
- How to insert a background picture in excel
- How to create Excel Chart from C#
- How to export excel chart from C#
- How to excel chart in C# picturebox
- C# data validation input box in excel file
- How to insert data to Excel file using OLEDB
- How to update data in Excel file using OLEDB
- How to export databse to excel file
- How to export DataGridView to excel file