How to Read Data from Excel by Using ADODB Object?

ADODB is one of the ways to read the data from Excel . There are totally 6 steps we have to follow to read data from Excel by using ADODB object. They are listed below:

  1. Creating a ADODB object
  2. Creating a connection String
  3. Writing an SQL query
  4. Creating a record set object
  5. Executing the SQL query and storing the result in record set object
  6. Then finally reading the data from that record set object

For example look at the below example to know more about how to read from Excel using ADODB object


//Path of the file from where you want to read the data
Set ODB=CreateObject(“adodb.Connection”)

//Creating  the ADODB object

ODB.ConnectionString= “Provider=Microsoft.Ace.Oledb.12.0; Data Source=”&strfilepath&”; Extended Properties=Excel 8.0″

sql= “Select * from Create_Emp”

//writing SQL query to fetch the data from Excel

Set oRec=CreateObject(“adodb.Recordset”)

//Creating the Recordset object

oRec.Open sql,ODB

//open the recordset object  and executing the SQL  query

//Reading the values from the filed
    msgbox strFirstName

//finally we have to close opened resources ( data base object and record set object)