Reading and Updating MS Access Database Using ADODB in UFT

In this article, I will show you how to read and update an MS Access Database using an ADODB connection in UFT/QTP. To understand it practically with example we will be using an Employee Table.

Let’s say we have a database named “UFTTestDB”. In that database, there is a table “Employee” that contains the employee details of an organization as shown below.

read Access Database Using ADODB

In order to connect MS Access Database using ADODB, we need to have a Connection String that would establish a connection between UFT and MS Access Database. We are going to use a connection string that is supported by both the older version(.mdb) and the latest version(.accdb) of MS Access Database. 

Reading MS Access Database Using ADODB

We can use the following code to read the MS Access Database

Updating MS Access Database Using ADODB

Let’s say we have a database named “UFTTestDB”. In that database, there is a table “Employee” that contains the employee details of an organization as shown below.
Updating-MS-Access-Database-Using-ADODB
Let’s update the salary of Employee Kelvin from 10000 to 12500. The SQL query to update Kelvin’s record would be “Update Employee Set Salary = 12500 where EmpName=’Kelvin'”. We can use the following code to execute an update query.

This is how the table will look after the execution of the code. The salary of the employee will be updated in the Employee table.

Updating-MS-Access-Database-Using-ADODB-2

Recommended Posts

Leave a Reply