SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Oct 2004
    Location
    Hyderabad
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Database Values into a excel sheet or any file

    Hi All,
    I want to make a database check by making an ODBC connection and retreiving some data values giving a query in the script, after the resultset is retrieved i want to palce the values in an excel sheet or any word doc or any as such file
    Is this possible, if so how to do the same?
    Thanks
    Ruben

  2. #2
    Member
    Join Date
    Oct 2004
    Location
    NY
    Posts
    30
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Database Values into a excel sheet or any file

    Hi,

    Here is an example we used in our script. First we set-up an ODBC connection under Administrative tools to connect to the database

    Then in QTP we write the following code something like this:

    'Create ODBC connection object and activate
    Set conActive = CreateObject("ADODB.Connection")
    conActive.Open "DSN=DSN Name"
    Set GetActiveConnection = conActive
    Set cmdTemp = CreateObject("ADODB.Command")
    cmdTemp.ActiveConnection = conActive

    'SQL command
    cmdTemp.CommandText = "SELECT * FROM TableName WHERE ID =1"

    SET recTemp = cmdTemp.Execute()

    'Write data from database to datatable
    counter = 1
    While Not recTemp.eof
    DataTable.SetCurrentRow(counter)
    DataTable.Value("A",dtGlobalSheet) = recTemp.fields(0).value

    recTemp.MoveNext
    counter = counter+1
    DataTable.SetCurrentRow(counter)
    Wend

    'Release resources
    Set conActive = Nothing
    Set cmdTemp = Nothing

    'Get the value from the datatable and assign it to a variable
    datavalue = DataTable.RawValue("A")

    MsgBox "This is the value " & datavalue & " that got retrieved from the database to the data table in QTP"

    '========================
    I hope this helps!!

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Location
    Hyderabad
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Database Values into a excel sheet or any file

    dear mkdz,
    your piece of code indeed has been very helpful.
    Thanks a million!!!!

    Ruben

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:48 PM.

Copyright BetaSoft Inc.