Objective
To develop a Windows application using c#.net to insert, search, and update records in M.S.Excel-2007 file using OleDb Connection.
Design
![Design]()
Design the form as above with a DataGridView, 3 Labels, 3 TextBoxes, and 9 buttons.
Introduction
As we want to use OleDb Connection include the namespace.
For accessing records from the M.S.Excel-2003 file we use the 'Jet' driver.
But, for accessing records from M.S. Excel-2007 file we use the 'Ace' driver.
In this application, we will search a record by taking input from the InputBox. For this, we have to add a reference to Microsoft.VisualBasic.
Adding Reference to Microsoft.VisualBasic
Goto Project Menu ->Add Reference -> select 'Microsoft.VisualBasic' from the .NET tab.
In order to use this we have to include the namespace.
Creating a primary key in the Data Table
In this app., we use the Find() method to search a record, which requires details of the primary key column. Database tables are provided using a statement.
But as we don't have any primary key column in the M.S. Excel sheet, we have to create a primary key column in the data table.
Example
Pointing to the current record in Table
After searching for a record, we have to get the index of that record so that we can navigate the next and previous records in the correct order.
Example
Code
Note. The 'xldb.xlsx' file is provided in the xloledb07.zip file along with the source code.