Exporting the Results of a Query to Data Table - QTP

We can export the Fields collection of a Recordset to a QTP data table. One issue that we might want to avoid is the spaces in the column name of the data table. To do that we should replace each space character in the column name from a query with an "__" character:

'First create a data table to export the data
'create a output sheet
Set outSheet = DataTable.AddSheet ("Output")
Dim adoRecordSet
strSQL = "Select * from Tablel"
Set adoRecordSet = adoCon.Execute (strSQL)
Dim fid
'Loop through each field and get the name
'to create the data table parameters
For each fid in adoRecordSet.Fields
outSheet.AddParameter Replace(fld.name," ","-")
Next
'Loop through all the rows of the query
While adoRecordSet.eof()
'Loop through all the columns of the row
For each fid in adoRecordSet.Fields
outSheet.GetParameter(Replace(fld.name," ","_")).value = fld.value
Next
'Move on to the next record
adoRecordSet.MoveNext
Wend
Set adoRecordSet = Nothing


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics