Micro Focus QTP (UFT) Forums
QTP Database conenction and parameterization of the values - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: QTP Database conenction and parameterization of the values (/Thread-QTP-Database-conenction-and-parameterization-of-the-values)

Pages: 1 2 3 4 5


RE: QTP Database conenction and parameterization of the values - somisays - 07-25-2008

Dear Siri,

This is the Code...Hope it works out for you..
I tested my version on my PC By using different table...
Let me know the result....



Code:
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = ("DSN=devmitg;username=xxx;password=yyy;")
Conn.Open
Set rs = Conn.Execute("Select Code, Meaning From TB_AMS052_Codes Where Code_Nam = 'Pole' ")

For each fields in rs.fields
DataTable.GlobalSheet.AddParameter fields.name , ""
Next
rs.MoveFirst

iRow = 1
Do
       DataTable.SetCurrentRow iRow
       DataTable("Code",dtGlobalSheet) = rs.fields("Code")
       DataTable("Meaning",dtGlobalSheet) = rs.fields("Meaning")
       iRow = iRow + 1
       rs.MoveNext
loop until rs.EOF
    

Conn.close

Set Conn = Nothing
Set Rs = Nothing



RE: QTP Database conenction and parameterization of the values - siri - 07-28-2008

hi sridhar ,

The test run cannot continue due to an unrecoverable error.

Wrong number of arguments or invalid property assignment: 'DataTable.GlobalSheet.AddParameter'


I am getting an error at this line itself .
I am getting the access to databse and gettign data from there to the msg box

But i am noit able to put them into the datatable of qtp


RE: QTP Database conenction and parameterization of the values - siri - 07-28-2008

Hi Sridhar ,

The following code is working ,but here in the test results pane it showing me the data in the data table but not in the Expert view window .
I believe we need to save so any function to save such as rs.save



Code:
'Data base connection'

                   Set conn=CreateObject("ADODB.Connection")
                                 conn.Open("DRIVER={Oracle in OraHome92};SERVER=DEVMITG;UID=ITL_ASSET;PWD=ITL_ASSET;DBQ=DEVMITG")
'rs connection record set'
                Set rs = CreateObject("ADODB.recordset")

                
' Specify the query'

                               sql = "Select Code, Meaning From TB_AMS052_Codes Where Code_Nam = 'Pole' "      
'ctr=0
                                         
'Execute the Query’
                rs.open sql,conn  
                
    'Get the no records returned by query’
'                           Code.GetROProperty (Property, [PropertyData])




        
'Adding a column to datatable’
For each fields in rs.fields

      
DataTable.GlobalSheet.AddParameter fields.name , ""

        Next
rs.MoveFirst

iRow = 1
Do
DataTable.SetCurrentRow iRow
'DataTable("Code",dtGlobalSheet) = rs.fields("Code")
DataTable("Meaning",dtGlobalSheet) = rs.fields("Meaning")
iRow = iRow + 1
rs.save
rs.MoveNext
loop until rs.EOF




       'Get the values from the Meaning column’
                

                                              While(NOT rs.EOF)
'                                        ctr=ctr+1
'                                            For i=1 to Recordcount
'                                                   Msgbox rs.Fields("code "+"meaning")
'                                                   Msgbox (rs.Get Row )
'                                                   Msgbox rs.Fields("Meaning")
'                                             DataTable.SetCurrentRow(i)

                                            
'Writing the data to the datatable’
'                      DataTable("Meaning",DtGlobalSheet) = rs.Fields("Meaning")                
                                                 rs.MoveNext
'                                                 Next
'                                            ctr=ctr+1
                                                 wend
'                                                                       Msgbox (ctr-1)

'close the database connection’
'DataTable.Export "C:\DatabaseExample.xls"
                    rs.close
                    conn.close



RE: QTP Database conenction and parameterization of the values - siri - 07-28-2008

Hi Sridhar,
According to athe above scritp i am able to get the data from the database to data table .

But is it is not saving in the expert view only saving i nthe test results pane .
I am forwarding you the screenshots of the same


RE: QTP Database conenction and parameterization of the values - somisays - 07-28-2008

Dear Siri,
The data is going to store only in runtime datatable is test results pane.So if you want the data then you have to use the following...

DataTable.Export "C:\DatabaseExample.xls"

So use the export command to get the data.


RE: QTP Database conenction and parameterization of the values - siri - 07-28-2008

hi sridhar ,

Thanks for hte great help .

I could get the data .
into the excelsheet on to the desktop.

Thanks a lot again .

Learning a lot from this forums helping me a lot .

I need to get the row count thats it i will do it thanks again
If any quesries will post



Code I used :

Great its working





Code:
'Data base connection'

                   Set conn=CreateObject("ADODB.Connection")
                                 conn.Open("DRIVER={Oracle in OraHome92};SERVER=DEVMITG;UID=ITL_ASSET;PWD=ITL_ASSET;DBQ=DEVMITG")


'rs connection record set'

                Set rs = CreateObject("ADODB.recordset")

                
' Specify the query'

                               sql = "Select Code, Meaning From TB_AMS052_Codes Where Code_Nam = 'Pole' "      
''Execute the Query’
                rs.open sql,conn  

'‘Adding a column to datatable’
For each fields in rs.fields

      
DataTable.GlobalSheet.AddParameter fields.name , ""

        Next
rs.MoveFirst

iRow = 1

Do
DataTable.SetCurrentRow iRow
DataTable("Code",dtGlobalSheet) = rs.fields("Code")
DataTable("Meaning",dtGlobalSheet) = rs.fields("Meaning")
iRow = iRow + 1
'rs.save
rs.MoveNext
loop until rs.EOF



'Get the values from the Meaning column’
                

                                              While(NOT rs.EOF)
rs.MoveNext
wend
DataTable.Export "C:\Documents and Settings\501404673\Desktop\data.xls"

    rs.close
                    conn.close



RE: QTP Database conenction and parameterization of the values - surya_7mar - 07-29-2008

i think you got the solution


RE: QTP Database conenction and parameterization of the values - siri - 08-04-2008

hi surya,

Have u tried the flex builder


RE: QTP Database conenction and parameterization of the values - surya_7mar - 08-04-2008

i didnt get chance to try it.


RE: QTP Database conenction and parameterization of the values - gammaflare - 08-06-2008

Wow.....that was incredible and wow Somisays has got lot of patience.........