Database Scripts-I: 1) Get Test Data From A Database and Use in Data Driven Testing (Through Scripting)
Database Scripts-I: 1) Get Test Data From A Database and Use in Data Driven Testing (Through Scripting)
Database Scripts-I
1) Get Test Data From a Database and use in Data Driven Testing
(through Scripting)
1) Dim con,rs
2) Set con=createobject("adodb.connection")
3) Set rs=createobject("adodb.recordset")
4) con.provider="microsoft.jet.oledb.4.0"
5) con.open"C:\Documents and Settings\admin\My
Documents\Gcreddy.mdb"
6) rs.open"select*from Login",con
7) Set ex=createobject("Excel.Application")
8) Set a=ex.workbooks.open("C:\Documents and Settings\admin\My
Documents\Gcreddy.xls")
9) Set b=a.worksheets("sheet1")
10) i=1
11) Do While Not rs.EOF
12) b.cells (i,1).value=rs.fields("agent")
13) b.cells(i,2).value=rs.fields("password")
14) rs.movenext
15) i=i+1
16) Loop
17) a.save
18) a.close
Const adOpenStatic = 3
Const adLockOptimistic = 3
objConnection.Open _
"Provider=SQLOLEDB;Data Source=atl-sql-01;" & _
"Trusted_Connection=Yes;Initial Catalog=Northwind;" & _
"User ID=fabrikam\kenmyer;Password=34DE6t4G!;"
objRecordSet.MoveFirst
Wscript.Echo objRecordSet.RecordCount
Const adOpenStatic = 3
Const adLockOptimistic = 3
objConnection.Open _
"Northwind;fabrikam\kenmyer;34ghfn&!j"
objRecordSet.MoveFirst
Wscript.Echo objRecordSet.RecordCount
Const adOpenStatic = 3
Const adLockOptimistic = 3
objConnection.Open _
"Provider= Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=inventory.mdb"
objRecordSet.Open "SELECT * FROM GeneralProperties Where
ComputerName = 'Computer1'", _
objConnection, adOpenStatic, adLockOptimistic
objRecordSet.MoveFirst
objRecordSet2.MoveFirst
Do Until objRecordset.EOF
Wscript.Echo objRecordset.Fields.Item("ComputerName")
Wscript.Echo objRecordset.Fields.Item("OSName")
objRecordSet.MoveNext
Loop
Do Until objRecordset2.EOF
Wscript.Echo objRecordset2.Fields.Item("DriveName"), _
objRecordset2.Fields.Item("DriveDescription")
objRecordSet2.MoveNext
Loop
objRecordSet.Close
objRecordSet2.Close
objConnection.Close
Const adOpenStatic = 3
Const adLockOptimistic = 3
objConnection.Open _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = eventlogs.mdb"
objRecordSet.MoveFirst
objRecordSet.Close
objConnection.Close
Database Scripts-II
1) Insert Data into a database table using Database Command
Object
Dim objCon,objCom
Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\gcreddy.mdb;"
Set objCom=Createobject("ADODB.Command")
objCom.ActiveConnection=objCon
objCon.Close
Set objCom=Nothing
Set objCon=Nothing
Dim objCon,objCom,strEmpName,intEmpNo,intEmpSal,intRowcount,i
Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\gcreddy.mdb;"
Set objCom=Createobject("ADODB.Command")
objCom.ActiveConnection=objCon
Datatable.AddSheet("input")
Datatable.ImportSheet "C:\gcreddy.xls",1,"input"
intRowcount=Datatable.GetSheet("input").GetRowCount
Msgbox intRowcount
For i=1 to intRowcount step 1
DataTable.SetCurrentRow(i)
strEmpName= DataTable.Value(1,"input")
intEmpNo= DataTable.Value(2,"input")
intEmpSal= DataTable.Value(3,"input")
objCom.CommandText="insert into Emp values( '"&strEmpName&"
',"&intEmpNo&","&intEmpSal&")"
objCom.Execute
Next
objCon.Close
Set objCom=Nothing
Set objCon=Nothing
Do Until objRs.EOF=True
x=objRs.Fields("EMPName")
For j= 2 to Rc
y=mySheet.cells(j,"A")
If x=y Then
Reporter.ReportEvent micPass,"Res","Name: "& y &" Available"
' Else
'Reporter.ReportEvent micFail,"Res","Name: "& y &" Not Available"
End If
Next
objRs.MoveNext
Loop
objExcel.Quit
Set objExcel=Nothing
objRs.Close
objCon.Close
Set objRs=Nothing
Set objCom=Nothing
http://www.gcreddy.com