qtp script to connect access database

2
Fore more QTP Realtime scripts, visit www.ramupalanki.com Function obj_UDF_getRecordset (strFileName, strSQLStatement) Dim objAdCon, objAdRs Set objAdCon = CreateObject(“ADODB.Connection”) objAdCon.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=”&strFileName & “;Readonly=True” If Err 0 Then Reporter.ReportEvent micFail,”Create Connection”, “[Connection] Error has occured. Error : ” & Err Set obj_UDF_getRecordset = Nothing Exit Function End If Set objAdRs = CreateObject(“ADODB.Recordset”) objAdRs.CursorLocation=3 ‘ set the cursor to use adUseClient – disconnected recordset objAdRs.Open strSQLStatement, objAdCon, 1, 3 While objAdRs.EOF=false For i=0 to 4 msgbox objAdRs.fields(i) Next objAdRs.moveNext Wend If Err0 Then Reporter.ReportEvent micFail,”Open Recordset”, “Error has occured.Error Code : ” & Err Set obj_UDF_getRecordset = Nothing Exit Function End If Set objAdRs.ActiveConnection = Nothing objAdCon.Close Set objAdCon = Nothing

Upload: ramu-palanki

Post on 04-Apr-2015

278 views

Category:

Documents


6 download

DESCRIPTION

QTP,VBScript,qtp script,qtp scripts,Automation,automation framework,automation estimation technique,automation estimation technique, QTP Interview questions,QTP real time scripts,sample vbscripts,QTP Sample Certification questions, qtp exam questions, hp qtp certification questions, QTP Certification HPO-M16 - Skill Review Test,QTP Guide, QTP Testing, Quick Test, QuickTest Professional, quicktest Pro,quicktest professional,qtp tutorial,qtp 10 tutorial,automation frameworks, qtp framework, test automation by qtp

TRANSCRIPT

Page 1: QTP Script to Connect Access Database

Fore more QTP Realtime scripts, visit www.ramupalanki.com

Function obj_UDF_getRecordset (strFileName, strSQLStatement)

Dim objAdCon, objAdRs

Set objAdCon = CreateObject(“ADODB.Connection”)

objAdCon.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=”&strFileName & “;Readonly=True”If Err 0 ThenReporter.ReportEvent micFail,”Create Connection”, “[Connection] Error has occured. Error : ” & ErrSet obj_UDF_getRecordset = NothingExit FunctionEnd IfSet objAdRs = CreateObject(“ADODB.Recordset”)objAdRs.CursorLocation=3 ‘ set the cursor to use adUseClient – disconnected recordsetobjAdRs.Open strSQLStatement, objAdCon, 1, 3

While objAdRs.EOF=falseFor i=0 to 4msgbox objAdRs.fields(i)NextobjAdRs.moveNextWend

If Err0 ThenReporter.ReportEvent micFail,”Open Recordset”, “Error has occured.Error Code : ” & ErrSet obj_UDF_getRecordset = NothingExit FunctionEnd If

Set objAdRs.ActiveConnection = Nothing

objAdCon.CloseSet objAdCon = Nothing

Set obj_UDF_getRecordset = objAdRs

End Function

Set rsAddin = obj_UDF_getRecordset(“C:\Documents and Settings\mohank\Desktop\Login.mdb”, “Select * from Login”)