Wednesday, July 2, 2014

Fetching Database Records using QTP

How to retrieve data from database using scripts

We can use ADODB.Recordset to get the recordset object.
Set  MyRecordSet=CreateObject(“ADODB.Recordset”)

Properties and Methods of Recordset object:

The properties and methods of Recordset object are veryuseful in getting the database records.

Recordset Properties:

RecordSet Properties
Description
AbsolutePage
Page of current position
AbsolutePosition
Current position
ActiveConnection
Active Connection Object
BOF
Beginning of File
Bookmark
Bookmark of current position
CacheSize
Number of records cached
CursorLocation
Server or Client
CursorType
Forward, Static, Dynamic, Keyset
EOF
End of File
EditMode
Whether or not an edit is in progress
Filter
What kind of records to hide
LockType
Record lock type for edits or updates
MaxRecords
Maximum number of records to retrieve
PageCount
Total number of pages
PageSize
Number of records per page
RecordCount
Total number of records
Source
Source Command Object
Status
Status of last action



Recordset Methods:

Recordset Methods
Description
AddNew
Add a new record to the RecordSet
CancelBatch
Cancel pending batch updates
CancelUpdate
Cancel pending update
Clone
Copy the RecordSet
Close
Close the RecordSet
Delete
Delete current record
GetRows
Retrieve multiple records
Move
Move the record pointer to a specific record
MoveNext
Move the record pointer to the next record
MovePrevious
Move the record pointer to the previous record
MoveFirst
Move the record pointer to the first record
MoveLast
move the record pointer to the last record
NextRecordSet
Load the next RecordSet in a multi-set query
Open
Open the RecordSet (execute the query)
Requery
Re-execute the last query executed
Resync
Synchronize the data with the server
Supports
Determine if a feature is supported by provider
Update
Update the current record
UpdateBatch
Update pending batched record updates


Tuesday, July 1, 2014

QTP Functions-Part 2


CDate Function:

Returns an expression that has been converted to a variant of subtype Date.

Syntax:

CDate (date)

date-any valid date expression

CDate() function uses IsDate() function to check if date can be converted to a date or time.
CDate recognizes date formats according to the locale setting of your system.

Example:

Dim strDate,strDate1,strTime,strTime1

strDate="April 10, 2010" 'Define Date

strDate1=CDate(strDate)     'Convert to Date datetype

strTime="2:30:45 AM"     'Define Time

strTime1=CDate(strTime)  'Convert to Date datetype

msgbox "Date : "&strDate1&", Time : "&strTime1


Output: