Saturday, 10 August 2013

How to Connect to a Database in QTP

Const adOpenStatic = 3
Const adLockOptimistic = 3 Const adUseClient = 3 Set objConnection = CreateObject("ADODB.Connection") Set objRecordset = CreateObject("ADODB.Recordset") objConnection.Open "DRIVER={Microsoft ODBC for Oracle};UID=;PWD=" objRecordset.CursorLocation = adUseClient objRecordset.CursorType = adopenstatic objRecordset.LockType = adlockoptimistic ObjRecordset.Source = "select field1,field2 from testTable" ObjRecordset.ActiveConnection = ObjConnection ObjRecordset.Open 'This will execute your Query If ObjRecordset.recordcount>0 Then    Field1 = ObjRecordset("Field1").Value    Field2 = ObjRecordset("Field2").Value End If

No comments:

Post a Comment