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 map the test cases to requirements in QC?

4 Answers   IBM,


what is Synchronization point in QTP?Can anybody give a perfect example on it Thanks in advance

5 Answers  


Use of Debug Viewer?

1 Answers  


Explain the types of object repository?

0 Answers  


how do u handle an object with out name in our application using QTP 9.2?

0 Answers   CTS,


Local Obj Repository and SOR are editable know, y we have to edit those.. i mean in which situation we need to edit those and how to do..? pls help me..

2 Answers  


I have below user Defained function function AddTwo(ByVal a, ByVal b) Dim Ans Ans=a+b MsgBox Ans End function Now my question comes here...from given below methods which method is right to call above function?Which is Wrong and why? 1. AddTwo(2,4) 2. Call AddTwo(2,4) 3. AddTwo 2,4 4. Call AddTwo 2,4

1 Answers  


What is synchronization point in QTP?

0 Answers  


How to Analyze the Checpoint results by Standard Checpoint?

1 Answers  


Did u use check points during ur work experience ?

3 Answers   FedEx,


Our company is having a windows client server application developed in vb.net. so there is a treeview and i am not in a position to record the click events in QTP. so kindly help. Vivek

0 Answers  


How we can differentiate between stand alone application and web application in QTP?

3 Answers   Deloitte,


Categories