How to update data in Excel file using OLEDB
In the previous examples, we relied on the Microsoft Excel 12.0 Object Library to perform read and write operations on Excel files. However, in C#, an alternative approach allows us to manipulate cell content in an Excel file without utilizing the Excel Object model. This can be achieved by using OLEDB (Object Linking and Embedding Database) technology.
System.Data namespace
To execute these operations, we employ components such as OleDbConnection, OleDbDataAdapter, and DataSet within the System.Data namespace. These components provide the necessary functionalities to carry out tasks such as inserting, editing, deleting, and selecting cell content in an Excel file. Importing the System.Data namespace into the project is crucial to utilize these components effectively.
UPDATE command
When updating or modifying the content within a cell, we can employ the UPDATE command, similar to SQL operations, to seamlessly perform the desired modifications on the cell content.
Sample UPDATE sql
The following picture shows before and after update of the Sheet.
Full Source C#Conclusion
Adopting this approach, developers can efficiently interact with Excel files, manipulating cell content without the direct dependency on the Excel Object model, thus offering enhanced flexibility and efficiency in Excel file manipulation.
- 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
- Read and Import Excel File into DataSet or DataTable
- How to insert data to Excel file using OLEDB
- How to export databse to excel file
- How to export DataGridView to excel file