How to insert data to Excel file using OLEDB
In the preceding examples, we employed the Microsoft Excel 12.0 Object Library to read from and write to Excel files. However, in C#, there is an alternative approach to manipulate cell content in an Excel file without utilizing the Excel Object. This can be accomplished by using OLEDB (Object Linking and Embedding Database) technology.
System.Data namespace
To implement these operations, it is necessary to import the System.Data namespace into the project. This namespace provides essential components such as OleDbConnection, OleDbDataAdapter, and DataSet to facilitate data manipulation tasks. When adding new content to a cell or inserting new content into the Excel file, we can utilize the INSERT command, similar to SQL operations, to seamlessly incorporate the desired data.
Sample UPDATE sql
The following picture shows before and after update of the Sheet.
Full Source C#Conclusion
Adopting this approach, developers can effectively interact with Excel files, performing various operations on cell content without the direct reliance 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 update data in Excel file using OLEDB
- How to export databse to excel file
- How to export DataGridView to excel file