Objective
To develop a Windows application for performing insert, search, update, and delete operations & navigation of M.S.Access 2007 records using ODBC connection.
Introduction
- Create a table in the M.S.Access 2007 file and populate it.
- In our application we use a 'stud.accdb' (M.S.Access 2007) file, which consists of a 'student' table.
- (Note: 'stud.accdb' is placed in 'prash_access07.zip' along with the source code)
Creating and Configuring ODBC Data Source (DSN)
Go to Start Menu -> Control Panel -> Administrative Tools -> Data Sources (ODBC).
![Control Panel]()
Click on the 'Add' button -> Select 'Microsoft Access Driver (*.mdb, *.accdb)' ->click on the 'Finish' button.
![Add button]()
Give a name to your Data Source
Click on the 'Select' button and select your M.S.Access 2007 file (*.accdb) -> OK -> OK.
![Select button]()
Your Data Source Name will be specified in the 'ODBC Data Source Administrator' window ->Click on the 'OK' button.
Thus, your Data Source (DSN) is configured.
Design
![Design]()
Design the form as above with a DataGridView, 3 Labels, 3 TextBoxes, and 10 buttons.
Introduction to Code
As we want to use ODBC Connection include the namespace.
For accessing records from the M.S.Access-2003 file, we use the 'Jet' driver.
But for accessing records from the M.S.Access-2003 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 a Reference
Goto Project Menu ->Add Reference -> select 'Microsoft.VisualBasic' from the .NET tab.
In order to use this we have to include the namespace.
ODBC connection string
Syntax
Ex
You just need to specify the Data Source Name(DSN) in the Connection String, no need to specify the driver details and path of the file, your DSN will take care of it.
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 primarykey column for database tables; this is provided using a statement.
But as we don't have any primary key column in the M.S.Access table, we have to create a primary key column in the data table.
Ex
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 show the next and previous records when we press the'>>'(next) and '<<'(previous) buttons.
Ex
Code