hi rajeshwar, try this method:
And call it within your steps/actions as here:
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.
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)
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.