Wednesday, April 20, 2011

How to connect to Database in QTP?

I recieved a mail by user(Swati) regarding database connectivity. thank you very much for suggestion...

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