Spread the love

How to Connect Database and Import Data From Database in Excel through VBScript or QTP

Spread the love

Table of Contents

Import Data From Database

In this post I tried a simple mechanism by a highly customizable code for connecting Database from Excel or QTP by using a VBA or QTP code.

Import Data From Database

The code will look like-

Dim cnnt
Set cnnt = CreateObject(“ADODB.Connection”)
cnnt.Provider = “SQLOLEDB”
//provider can be any…..like sql,mysql
cnnt.ConnectionString= ” Driver={SQL Server}; Server=127.0.0.1; Database=Northwind; UID=sa; PWD=”
cnnt.Open
Set recordSet = CreateObject(“ADODB.Recordset”)
Set recordSet1=cnnt.Execute(“Select * from Employees”)
Set objStream=CreateObject(“ADODB.Stream”)
recordSet1.Save objStream,1
Set objExcel=CreateObject(“Excel.Application”)
Set objSheet=CreateObject(“Excel.Sheet”)objSheet.Application.visible=true
objSheet.activesheet.cells (1,1).CopyFromRecordset recordSet1
objSheet.Saveas “D:database.xls”
objExcel.quit
Set objSheet =Nothing
recordSet1.Close

Import Data From Database




Spread the love
READ  Learn How to Work with XML with UFT in Fast and Effortless Manner
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love