QTP Script to Export Database Data to Excel Sheet

Import data from database to datatable

Script to export database data to excel sheet in qtp.

Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.provider="microsoft.jet.oledb.4.0"
con.open"d:\db.mdb"
rs.open"select*from EMP",con
Set ex=createobject("Excel.Application")
Set a=ex.workbooks.open("D:\Lak.xls")
Set b=a.worksheets("sheet1")
i=1
Do While Not rs.EOF
b.cells (i,1).value=rs.fields("empno")
b.cells(i,2).value=rs.fields("empname")
b.cells(i,3).value=rs.fields("empsal")
rs.movenext
i=i+1
Loop
a.save
a.close

Above written script is for exporting database data to already exisiting excel sheet.
Database has a table called EMP with columns empno,empname,empsal.The values of these columns are exported to excel sheet.

Excel Sheet Creation and Writing Data Into It

Data Driven Using Excel Sheet

Data Driven Using Notepad

SQL Queries Collection

Movie Songs Lyrics

1 comment:

Unknown said...

Hi, I am trying to execute a SQL query in VBscript(QTP) using connection and recordset objects

The script is working fine for all SQL queries but it is giving error as 'Missing keywords' whenever CASE statement is there in SQL Query. Same query is working fine if executed from backend(using PL/SQL Developer)

Can anyone provide me any clarification why this error is coming for SQL queries with CASE statements

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge