05-26-2010, 12:44 PM
Hi Guys,
Is there any way to Automate the feature provided by QTP to import data from a Database Table to DataSheet(Sheet>>Import>>From Database) where we can establish the connection and fetch the Data from a database table.
Can we acheive this using QTP object Model?
I have the information that data can be fetched from DB in following manner, just wondering if there's a Way to acheive Import Database feature of QTP DataSheet.
----------------------------------------------------------
Is there any way to Automate the feature provided by QTP to import data from a Database Table to DataSheet(Sheet>>Import>>From Database) where we can establish the connection and fetch the Data from a database table.
Can we acheive this using QTP object Model?
I have the information that data can be fetched from DB in following manner, just wondering if there's a Way to acheive Import Database feature of QTP DataSheet.
----------------------------------------------------------
Code:
set con = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
con.Open("Provider=sqloledb.1;Data Source=RAJESHWAR;Initial Catalog=Northwind;User Id='sa';Password='sa'")
rs.Open "select Top(10) * from customers",con
DataTable.GlobalSheet.AddParameter "CustomerId",""
DataTable.GlobalSheet.AddParameter "CompanyName",""
DataTable.GlobalSheet.AddParameter "CustomerName",""
i=1
Do while Not rs.EOF
DataTable.GlobalSheet.SetCurrentRow(i)
DataTable.Value("CustomerId") =rs.Fields.Item(0)
DataTable.Value("CompanyName") =rs.Fields.Item(1)
DataTable.Value("CustomerName") =rs.Fields.Item(2)
i=i+1
rs.MoveNext
Loop
con.Close