Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DatabaseExample
#1
Not Solved
Hi,
This is a How to connect to MS Access Database(Flight32.mdb).
1)Create a Data Source name by following these steps.
Control Panel...>Administrative Tools...>Data Sources(ODBC)
Click on Add...>Select Drive For Microsoft Access Driver(>mdb)

Give the Datasource name and select the database...>
C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app

2)Paste the following Code in the QTP Expert View Window

Code:
Connect to the flight 32 database
Set Conn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.recordset")

Conn.Open("DSN=Flight32")

'Specify the query

sql = "Select * from Orders"

'Set the recordset cursor type
Rs.CursorType = 1 'set to a Keyset cursor type

'Execute the Query
Rs.Open sql,Conn

'Get the no records returned by  query
Recordcount = Rs.RecordCount

'Adding a column to datatable
DataTable.GlobalSheet.AddParameter "Customer_Name",""


'Get the values from the customer_Name column

While(NOT Rs.EOF)

'Msgbox Rs.Fields("Customer_Name")
For i=1 to Recordcount
    DataTable.SetCurrentRow(i)

    'Writing the data to the datatable
    DataTable("Customer_Name",DtGlobalSheet) = Rs.Fields("Customer_Name")
    
Rs.MoveNext
Next

wend

'Exporting the Datatable to C:\DatabaseExample.xls
DataTable.Export "C:\DatabaseExample.xls"

'close the database connection

Conn.close

Set Conn = Nothing
Set Rs = Nothing

Hope this is going to be helpfull for evreyone.
Reply


Messages In This Thread
DatabaseExample - by somisays - 06-16-2008, 12:01 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)