To Retrieve Column Names From Database Table in QTP-VBScript To Get Column Names From Table Present in Database

VB Script to get column names from database table(MS Access).

We have table "EMP" in database "db"(Microsoft Access).

EMP Table has following data in it.

EMPNO EMPNAME EMPSAL
1 Lakshmi 30,000
2 Laxmi 25,000
3 Latha 15,000

Check This Blog For SQL Queries

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
For i = 0 To rs.Fields.Count - 1
column_name=rs.Fields(i).Name
Msgbox column_name
Next

Output:

EMPNO
EMPNAME
EMPSAL

SQL Queries Collection
QTP Script for Connecting to database
QTP Script to export database data to excel sheet
QTP Script to import database data to datatable
Connecting to MSAcess,Oracle,SQL Server Database
Hindi and Telugu Songs Lyrics

1 comment:

Steve Langille said...

I am looking for something similar.

I need to find the first column that = Nav1 and place that column number into a variable so I can use it again later.

EX:

Here are some columns in my excel

A B C D E Nav1 Nav2 Nav3 Nav4

So I would need some code that would go into excel and come back with the number 6. Since Nav1 starts on column 6.

Note: The column location for Nav1 can change.

Thanks,
Steve
slang46188@aol.com

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge