How to Compare two database tables by using QTP?Please give
me code details.



How to Compare two database tables by using QTP?Please give me code details...

Answer / jagathi

'Get Two different data from two different Tables and
compare it;
'Two different Database and check their values.
' First Table Name - -> EmpTable
' Second Table Name ---> DeptTable
'Database ---> MS Access
' First Table Connection
Dim conn,rs
Set conn=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
conn.provider="microsoft.jet.oledb.4.0"conn.open"C:\db1.mdb"
' creating an object for the recordsetset
rs =CreateObject("ADODB.recordset")
' DB Query for selecting all the records available from
EmpTable
rs.open "select * from EmpTable",conn
' Adding Headings
datatable.GetSheet(1).addparameter "EMPLOYEE NO","
"datatable.GetSheet(1).addparameter " NAME","
"datatable.GetSheet(1).addparameter "DESIGNATION","
"datatable.GetSheet(1).addparameter " ADDRESS",""row=1
' Loop for each records
Do While not rs.EOF
datatable.SetCurrentRow(row)
datatable.Value("EMPLOYEE_NO",1) = rs.fields("EmpNo")
datatable.Value("NAME",1)=rs.fields("EmpName")
datatable.Value("DESIGNATION",1)=rs.fields("Designation")
datatable.Value("ADDRESS",1)=rs.fields("Address")
val1 = datatable.Value("NAME",1)row=row +1rs.movenext loop
' Second Table Operation
set rs1 =CreateObject("ADODB.recordset")
'DB Query for selecting all the records available from
DeptTable
rs1.open "select * from DeptTable",conn
datatable.GetSheet(1).addparameter "EMPNO_Dept",""
datatable.GetSheet(1).addparameter "EMPNAME_Dept",""
datatable.GetSheet(1).addparameter "DEPTNAME_Dept",""
' Assigning values from First row
row=1
do While not rs1.EOF
datatable.SetCurrentRow(row)
datatable.Value("EMPNO_Dept",1)=rs1.fields("EmpNo")
datatable.Value ("EMPNAME_Dept",1)=rs1.fields("EmpName")
datatable.Value("DEPTNAME_Dept",1)=rs1.fields("DeptName")
row=row +1rs1.movenextloop
' Create one more Column called ResultColumn
DataTable.GetSheet("Global").AddParameter"ResultColumn",""
cnt=DataTable.GetRowCount
For i=1 to cnt
DataTable.SetCurrentRow(i)
OldVal=DataTable.Value("NAME","Global")
NewVal = DataTable.Value("EMPNAME_Dept","Global")
' Comparing two NAME fields
If OldVal = NewVal Then
DataTable.Value("ResultColumn","Global") = oldVal
Reporter.ReportEvent micPass, "P","The Names Fields are
Equal "
else Reporter.ReportEvent micFail,"F","The Names Fields are
Not Equal"
End If
Next

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More QTP Interview Questions

how to reverse a string with out using string or predefined function,ex:string is " i love india". the output should be like this "i evol aidni"

3 Answers   Aspire,


On the website, the protocol has been changed https: to https what you will do? Tell me your approach?

0 Answers  


What are the types of Object Repository’s in QTP?

2 Answers   Crea,


how to retrive that the number of spaces are in a string ????

2 Answers   Liquid Hub,


Please anybody can tell the where can i get the information about pharma and bank testing, i put the pharma&bank projects in my resume, so i dont know what to tell about them, so where can i get the information and what we test for these, i need domain information, what r the screen we test?

0 Answers  






I have a drop down box to show selected number of records in result page.It contains 4 items like 10, 25,50 and 100. when i was recordes script for seelcting each item and checking selecting number of records in the result page( it is in the same page in the table format)it is generating a new page with same controls( objects) in the OR. how to avaid these in OR? is it possible to write DP for only these lines?, remaining(remaingin lines of code) objects i want use from OR only. One more problemis if change ( add /remove properties of an OBJECT in OR , my ( recorded )application is not running.

5 Answers   Virtusa,


What is the difference between two actions?

1 Answers   Wipro,


When I start recording any web application (either Mozilla or IE) QTP recognizes window instead of browser and also it does not show all the hierarchy tree of that particular web page. 1. Window("Mozilla Firefox").Check CheckPoint("Mozilla Firefox") 2. As everybody knows it should be browser("Mozilla Firefox").Check CheckPoint("Mozilla Firefox") I am using the windows vista, do you think it may be a problem of my settings in QTP or problem of my installation. Your kind responses will be appreciated. Thanks in advance. Satya

12 Answers  


hi what is the use of "dim" in automation objective model or any where what is the use of "dim" plz tell me

3 Answers  


What is Environment Variable and when we apply this in QTP?

4 Answers  


what is the hierarchy to use properties in descriptive programming

0 Answers  


i am entering wrong data or wrong password in a text box and click on submit button .i am getting a popup window with a message Please enter the correct password or data .How can i handle this situation by using QTP.

11 Answers   SAP Labs,


Categories