Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing Data from a Database
#6
Solved: 11 Years, 3 Months ago
hi rajeshwar, try this method:

Code:
Public Function DBQuery
    Set DBQuery = New DBConnect
End Function

Class DBConnect
'querying a 'SELECT' event within DB
    Public Function DBSelect(sqlSelect, itemCode)
            If Browser("URL:=http://environment.at/project/.*").Exist Then
                set conn = createobject("adodb.connection")
                conn.open "DSN=ENV_DEV_DB; UserID=userID; Password=password;"
                set rs = createobject("adodb.recordset")
            'get the date value from DB for an Event
                rs.open sqlSelect, conn
                dBitem = rs(itemCode)
                rs.close
                reporter.ReportEvent 2, "Data BASE:", "the Data within DB is: '" &  dBitem & "'"
            ElseIf Browser("URL:=http://environment.st/project/.*").Exist Then
                set conn = createobject("adodb.connection")
                conn.open "DSN=ENV_TST_DB; UserID=userID; Password=password;"
                set rs = createobject("adodb.recordset")
            'get the date value from DB for an Event
                rs.open sqlSelect, conn
                dBitem = rs(itemCode)
                rs.close
                reporter.ReportEvent 2, "Data BASE:", "the Data within DB is: '" &  dBitem & "'"
            ElseIf Browser("URL:=http://environment.ut/project/.*").Exist Then
                set conn = createobject("adodb.connection")
                conn.open "DSN=ENV_UAT_DB; UserID=userID; Password=password;"
                set rs = createobject("adodb.recordset")
            'get the date value from DB for an Event
                rs.open sqlSelect, conn
                dBitem = rs(itemCode)
                rs.close
                reporter.ReportEvent 2, "Data BASE:", "the Data within DB is: '" &  dBitem & "'"
            Else
                reporter.ReportEvent micFail, "ERROR:", "The browser was not found!"
            End If
        ' assigning the output value
        DBSelect = dBitem
    End Function
End Class

And call it within your steps/actions as here:

Code:
' get the Requested value from DB
DBRequested_Value = DBQuery.DBSelect (sqlSelect, "ValueFromDB")
' (sqlSelect, itemCode)
where for e.g:
sqlSelect = UCASE("SELECT CLB5VA as ValueFromDB FROM CSCLREP WHERE CLAINB = '80808' AND CLBHDT = '1100909' and CLWTNB='01'")
itemCode = "ValueFromDB"
or itemCode = "CLB5VA".
The 'IF' statements are used if you are testing on more than one environments. Remove IF if it is not necessary for your project.

On my project this code is working very good.
Reply


Messages In This Thread
Importing Data from a Database - by rajeshwar - 05-26-2010, 12:44 PM
RE: Importing Data from a Database - by Saket - 05-26-2010, 01:03 PM
RE: Importing Data from a Database - by rajeshwar - 05-26-2010, 02:48 PM
RE: Importing Data from a Database - by qtp-qa - 04-03-2012, 12:23 AM
RE: Importing Data from a Database - by lotos - 09-14-2010, 08:45 PM
RE: Importing Data from a Database - by lotos - 11-23-2010, 08:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Importing excel not working Adam82 6 13,543 11-05-2012, 05:22 PM
Last Post: Adam82
  it is possible import from excel to table with expected data of checkpoint database i sarcastic 0 2,253 08-05-2011, 04:42 PM
Last Post: sarcastic
Smile importing objects and properties to excel sheet sandy.jakhar 2 3,671 03-16-2011, 03:26 PM
Last Post: sandy.jakhar
  mapping database user to database kamalteja 4 4,663 11-03-2010, 11:58 AM
Last Post: kamalteja
  Data importing from excel using script vaigundamoorthy 3 3,666 05-19-2009, 04:53 PM
Last Post: lit_73

Forum Jump:


Users browsing this thread: 2 Guest(s)