Monday, June 22, 2009

How to retrieve the tooltip text of images?

We can retireve this using HTML Source file from View -> Source menu.After that for every image the alt tag attribute represents the value of tooltip text(of class tooltips_class32.).

alternatively using HTML DOM :
msgbox Browser("Google").Page("Google").WebEdit("q").Object.title

Sunday, June 21, 2009

procedures in pl/sql in Oracle

1.procedure can use the return statement to return the control back to calling subprogram.
2.function can return a values as well it can be used anywhere in a SQL statement.

create or replace procedure proc_highpayee
as
varEno NUMBER default 0;
begin
select eno into varEno from emp where sal = (select max(sal)from emp) and rownum =1;
return;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('No Data found for SELECT ');
end;

alter (DDL) commands in SQL?

DDL : Create,Drop,Truncate,Alter
DML: Insert,Update, Delete
DCL : Grant,Revoke,Commit,Rollback;
-- retrieving the duplicate name records only
select ename from emp e1 where 1 < (select count(*) FROM emp e2 WHERE e2.ename = e1.ename) --alter:to add ,modify and drop a column alter table add/modify
alter table drop column
select round(11.567, 0) from dual; --12
select round(11.567, 1) from dual; --11.6
select round(11.567, 2) from dual; --11.57
select round(11.567, 3) from dual; --11.567

Subprograms in PL/SQL?

select sal from emp where eno = func_highpayee;

--function declaration
create or replace function func_highpayee
return number
as
varEno NUMBER default 0;
begin
select eno into varEno from emp where sal = (select max(sal)from emp) and rownum =1;
return(varEno);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('No Data found for SELECT on ' );
end;

executing a proc or func:
begin
proc-name;
end;

exec proc-name;

Saturday, June 20, 2009

Set an Object Repositories List as Default for All New Actions in QTP?

'This example opens a test, configures an action's object repositories collection
'and saves the test.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'************************************************************************************************************************
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable
Dim lngPosition
' Open QuickTest
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible
' Open a test and get the "Login" action's object repositories collection
qtApp.Open "C:\Tests\Test1", False, False ' Open a test
Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories ' Get the object repositories collection object of the "Login" action
' Add MainApp.tsr if it's not already in the collection
If qtRepositories.Find("C:\MainApp.tsr") = -1 Then ' If the repository cannot be found in the collection
qtRepositories.Add "C:\MainApp.tsr", 1 ' Add the repository to the collection
End If
' If InnerWnd.tsr is moved down the list - place it back at position 1
If qtRepositories.Count > 1 And qtRepositories.Item(2) = "C:\InnerWnd.tsr" Then ' If there's more than one object repository and InnerWnd.tsr is in position 2
qtRepositories.MoveToPos 1, 2 ' Switch between the first two object repositories
End If
' If Debug.tsr is in the collection - remove it
lngPosition = qtRepositories.Find("C:\Debug.tsr") ' Try finding the Debug.tsr object repository
If lngPosition <> -1 Then ' If the object repository was found in the collection
qtRepositories.Remove lngPosition ' Remove it
End If
' Set the new object repository configuration as the default for all new actions
qtRepositories.SetAsDefault ' Set object repositories associated with the "Login" action as the default for all new actions
'Save the test and close QuickTest
qtApp.Test.Save ' Save the test
qtApp.Quit ' Quit QuickTest
Set qtRepositories = Nothing ' Release the action's shared repositories collection
Set qtApp = Nothing ' Release the Application object

Friday, June 19, 2009

Displaying a Sentence(each character) in Reverse Order using QTP VB Scripting

var1 = "Hi how are you?"
msgbox strreverse(var1)

Test and Run-time Object in QTP?

What is the difference between Test Objects and Run Time Objects ?
Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which a test object maps.

Can i change properties of a test object?
Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the Smart Identification for the object on which you use SetTOProperty function.

Can i change properties of a run time object?
No (but Yes also). You can use GetROProperty(”outerText”) to get the outerText of a object but there is no function like SetROProperty to change this property.
But you can use WebElement().object.outerText=”Something” to change the property.

Write test cases for Login page and Calculator?

First divide the scenarios for types of testing then again derive the sub scenarios for

1.Look and feel
2.Usability
3.Performance
4.Security
Authorization testing
Authentication testing
sql injection
cross scripting
5.Functionality

How to copy the contents of one table to another table in Oracle?

CREATE TABLE newTable AS SELECT * FROM emp WHERE sal > 2000;

insert into newTable SELECT * FROM emp WHERE sal > 2000 ; "to copy the contents"

insert into newTable SELECT * FROM emp WHERE 1> 2 ; "to copy the structure"


with the above statement the contents from the table emp will be copied to temp with the same structure as emp table.

Monday, June 15, 2009

How manys we can write vbscript statements in QTP?

1.Recording.
2.Manual writing.
3.Step Generator.
4.Descriptive Programming.

Thursday, June 4, 2009

Working with text filesin QTP ?

Creating Files
There are three ways to create an empty text file (sometimes referred to as a "text stream").

1.The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using the CreateTextFileMethod method.
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)



2.The second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set.
Dim fso, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting. FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)



3.A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set.
Dim fso, f1, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("c:\test1.txt")
Set f1 = fso.GetFile("c:\test1.txt")
Set ts = f1.OpenAsTextStream(ForWriting, True)


Adding Data to the File
Once the text file is created, add data to the file using the following three steps:
Open the text file.
Write the data.
Close the file.
To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object.
To write data to the open text file, use the Write, WriteLine, or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table.
Task
Method
Write data to an open text file without a trailing newline character.
Write
Write data to an open text file with a trailing newline character.
WriteLine
Write one or more blank lines to an open text file.
WriteBlankLines
To close an open file, use the Close method of the TextStream object.
Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage return/line feed). Be aware that the end of some strings may already have such nonprinting characters.
The following example demonstrates how to open a file, use all three write methods to add data to the file, and then close the file:[VBScript]
Sub CreateFile()
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
tf.WriteLine("Testing 1, 2, 3.")
' Write three newline characters to the file.
tf.WriteBlankLines(3)
' Write a line.
tf.Write ("This is a test.")
tf.Close
End Sub

Read:

' Read the contents of the file. Response.Write "Reading file
Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)

s = ts.ReadLine

Response.Write "File contents = '" & s & "'"

ts.Close

Moving, Copying, and Deleting Files
The FSO object model has two methods each for moving, copying, and deleting files, as described in the following table.
Task
Method
Move a file
File.Move or FileSystemObject.MoveFile
Copy a file
File.Copy or FileSystemObject.CopyFile
Delete a file
File.Delete or FileSystemObject.DeleteFile
The following example creates a text file in the root directory of drive C, writes some information to it, moves it to a directory called \tmp, makes a copy of it in a directory called \temp, then deletes the copies from both directories.
To run the following example, create directories named \tmp and \temp in the root directory of drive C:

' Get a handle to the file in root of C:\.

Set f2 = fso.GetFile("c:\testfile.txt")

' Move the file to \tmp directory. f2.Move ("c:\tmp\testfile.txt

' Copy the file to \temp.

f2.Copy ("c:\temp\testfile.txt")

' Get handles to files' current location.

Set f2 = fso.GetFile("c:\tmp\testfile.txt")

Set f3 = fso.GetFile("c:\temp\testfile.txt")

' Delete the files.

f2.Delete

f3.Delete

Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)

While not ts.atEndOfLine

s = ts.ReadLine

msgbox s

Wend

Working with excel files in QTP using "Excel.Application" class?

Set xlApp = CreateObject("Excel.Application")
Set xlWorkBook = xlApp.workbooks.add 'or Set xlbook=xlapp.activeworkbook
Set xlWorkSheet = xlWorkbook.worksheet.add 'or Set worksheet=xlbook.sheets(3)
xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cells
xlWorkSheet.Range("A1:A10").value = "text" 'Will set values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value = "Text" 'Will set the value of first row and first col
rowsCount = xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non blank value in the column A
colsCount = xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1st row
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet = Nothing
Set xlWorkBook = Nothing
Set xlApp = Nothing

Getting Child Objects in QTP?

Returns the collection of child objects contained within the object.

We can use description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for a checkboxe and then get all the checkboxes from the page


Dim obj_ChkDesc
Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”
Dim allCheckboxes, singleCheckBox
Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)

For each singleCheckBox in allCheckboxes
singleCheckBox.Set “ON”
Next

Sub ChildObjects_Example()'The following example uses the ChildObjects method to find all the'list objects on a Web page, and then to select an item in each list.

Set oDesc = Description.Create()

oDesc("micclass").Value = "WebList"

Set Lists = Browser("Mercury Interactive").Page("Mercury Interactive").ChildObjects(oDesc)NumberOfLists = Lists.Count()

For i = 0 To NumberOfLists - 1

Lists(i).Select i + 1

Next

End Sub


all the values are interpreted as regular expressions. To turn it off, use

oDesc(“Property1”).RegularExpression = False



type = checkbox
type = radio
class = weblist
class= webedit
class = image

in description object for list,textbox,image we can use micclass in description object

Hierarchy of test description ?

When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement.

If you specify a test object by its object repository name after other objects in the hierarchy have been described using programmatic descriptions, QuickTest cannot identify the object.

For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.

You can also use Browser("Index").Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting
from the Page object description).

However, you cannot use Browser(Desc1).Page(Desc1).Link("Example1"), since it uses programmatic descriptions for the Browser and Page objects but
then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot
locate it in the repository because the parent objects were specified using programmatic descriptions).

you can only start from OR, and move to DP So this will not work:
VBWindow(“title:=notgood”).VBButton(“clickme”).Click

How to use Description Object?

Used to create a Properties collection object.
Creates a new, empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object name in a step.


For example, the statements below instruct QuickTest to enter the text: MyName in the first WebEdit object in the Mercury Tours page with the name UserName


Set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"
When working with Properties objects, you can use variable names for the properties or values to generate the object description based on properties or values you retrieve during a run session. You can also create several Properties objects in your test if you want to use programmatic descriptions for several objects.

'Returns the number of Property objects in the Properties collection
PropCount = MyDesc.Count

ex2:
Dim obj_Desc
Set obj_Desc = Description.Create
obj_Desc("name").value = "q"
obj_Desc("class name").value = "web edit"
browser("Google").Page("Google").WebEdit(obj_Desc).Set "hi"

Working with Dictionary Objects

A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" '
Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
msgbox d("a") ' retrieves the Athens
a = d.Keys ' Get the keys
b = d.Items ' Get the items.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & space(1) & b(i) & vbnewline ' Create return string.
Next
msgbox s

How do we ensure we can close the correct browser?

Environment("env_BrowserHandle") = Browser("Browser).GetROProperty("hwnd")'Then

Browser("hwnd:=" & Environment("env_BrowserHandle")).Close

Select a Radio Button Option

'The following example uses the Select method to check if a radio group
'has the value of "Two", and, if not, selects the "Two" radio button.
Sub Select_Example2()

CurrentValue = Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").GetTOProperty("value")
If CurrentValue <> "Two" Then
Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"
End If
end sub


'The following example uses the Select method to select the Window
'item in a Web radio group in the seating preference section of
'the Mercury Tours application.
Sub Select_Example1()
Browser("Mercury Tours").Page("Find Flights").WebRadioGroup("seat pref").Select "Window"
End Sub


'selectin radion buttons from google home page
Browser("MonsterIndia.com - More_2").Page("Google").WebRadioGroup("meta").Select "#0" 'selecting "the web"
Browser("MonsterIndia.com - More_2").Page("Google").WebRadioGroup("meta").Select "cr=countryIN" ' selecting "pages from india"

'some of the inportant properties
items count
selected item index
all items
type :radio

Checking the status of a checkbox

Browser("MonsterIndia.com - More_2").Page("MonsterIndia.com - More").WebCheckBox("ctp").Set "ON"

var_ChkStatus=Browser("MonsterIndia.com - More_2").Page("MonsterIndia.com - More").WebCheckBox("ctp").GetROProperty("checked")

msgbox var_ChkStatus '1

Browser("MonsterIndia.com - More_2").Page("MonsterIndia.com - More").WebCheckBox("ctp").Set "ON"

var_ChkStatus=Browser("MonsterIndia.com - More_2").Page("MonsterIndia.com - More").WebCheckBox("ctp").GetROProperty("checked")

msgbox var_ChkStatus '0

'checking for a particular item in the list box

'checking for a particular item in the list box and select it
var_SearchItem = "Hyderabad"
var_ItemsCount = Browser("MonsterIndia.com - More").Page("MonsterIndia.com - More").WebList("loc").GetROProperty("items count")
For i =1 to var_ItemsCount
var_Item = Browser("MonsterIndia.com - More").Page("MonsterIndia.com - More").WebList("loc").GetItem(i)
If ucase(var_SearchItem) = ucase(var_Item) Then
msgbox "found"
Exit for
End If
Next

Note:
While selecting an item from a list box the index starts from 0
and while getting an item from a list box the index starts from 1

Browser("MonsterIndia.com - More").Page("MonsterIndia.com - More").WebList("loc").Select i-1

'some of the important properties of the list object
items count
selected item index
all items
selected items count
value : selected item value

How to chek whether an object exists or not?

var_Exist = Dialog("Login").WinEdit("Agent Name:").Exist
msgbox var_Exist 'Return true if object exists otherwise false

Adding a Parameter to RunTime DataTable in QTP

The following example uses the GetSheet method to return the "MySheet" sheet of the run-time Data Table in order to add a parameter to it.
MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")
You can also use this to add a parameter to the "MySheet" local sheet (note that no value is returned).
DataTable.GetSheet ("MySheet").AddParameter "Time", "8:00"
myparam = DataTable. LocalSheet.AddParameter("Time", "5.45")
MsgBox myparam 'output is 5.45

Displaying a Sentence( of words) in Reverse Order using QTP VB Scripting

str="I'm QuickTestProfessionall.Do you know me?"

arrStrings = Split(str,space(1))

msgbox ubound(arrStrings)

vstrReverse=empty

For each arrStr in arrStrings

vstrReverse = strReverse(arrStr) & space(1) & vstrReverse

msgbox arrStr'each string separated by a single space

Next

msgbox vstrReverse




or

Public Function ReverseString(ByVal InputString As String) _
As String

Dim lLen As Long, lCtr As Long
Dim sChar As String
Dim sAns As String

lLen = Len(InputString)
For lCtr = lLen To 1 Step -1
sChar = Mid(InputString, lCtr, 1)
sAns = sAns & sChar
Next

ReverseString = sAns

End Function

Can we spy on a Virtual Object?

we can't get the properties....? More info yet to get.....?

Disable recognition of vrtual objects while recording?

"Disable recognition of vrtual objects while recording" option can be set from::
Tools-> Options -> General

How do we set Video Record session from QTP?

Tools -> Options -> Run

How do we know current iteration value from Environment variable?

msgbox Environment.Value("ActionIteration")
msgbox Environment.Value("TestIteration")
Indicates which action iteration is currently running.

Conditional loops int QTP?

Do...Loop Statement
Repeats a block of statements while a condition is True or until a condition becomes True.
Do [{While Until} condition]
[statements]
[Exit Do]
[statements]
Loop
Or, you can use this syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [{While Until} condition]
ex:
Do
Loop While False
Do
Loop Until True
While...Wend Statement
Executes a series of statements as long as a given condition is True.
While condition
Version [statements]
Wend
For...Next Statement
Repeats a group of statements a specified number of times.
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next
For Each...Next Statement
Repeats a group of statements for each element in an array or collection.
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]

What are the step commands available in QTP?

Step Into
Step Over
Step out
Run to step
Debug from step

Wednesday, June 3, 2009

What is a virtual object?

Virtual object enable you to record and run test on objects that are not normally recognized by QTP. We can teach QTP to recognize any area of your application as an object by defining it as a virtual object. Sometimes QTP may not recognizes some objects, in this kind of situations we use virtual object .It uses the coordinates of the object to map it to Microsoft Standard Objects.

Tuesday, June 2, 2009

When does the descriptive programming preferred?

1.When we start the automation even before the application comes for automation and only some document related to the application available.
2.when object repository size exceeds its maximum size .
3.when there are dynamic objects in the application.
4.execution is faster with descriptive programming .
5.when object repository is read only and we can't add any more objects..


We can write the desc pgmg script on a particular object without adding it to the object repository file by giving the physical description of the object directly in place of the logical name.

Associating a library file to test at RunTime manually in QTP?

If we associate a library file(classes,functions and procedures) at Run time then scope of the variables or objects of that library file will not be available to all the actions except to the only action where execute file statement is executed..

If we want the scope to be across all the actions then we have two ways of doing it:

1.attach that library file manually from File->Settings -> Resources.
2.use the below code which you need to run before qtp tool is open
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible
' Open a test and get its libraries collection
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object
' Add Utilities.vbs if it's not in the collection
If qtLibraries.Find("C:\lib1.vbs") = -1 Then ' If the library cannot be found in the collection
msgbox "not assosiated"
qtLibraries.Add "C:\lib1.vbs", 1 ' Add the library to the collection
End If
Set qtLibraries = Nothing ' Release the test's libraries collection
Set qtApp = Nothing ' Release the Application object
RunAction "Action2", oneIteration

When do we use function or action?

function can be used when
1.you have code which you want to reuse across all the projects.
2.when there is no dependency on Object Repository.

other than the above scenarios we go for actions..
1.Actions are project dependent

Validating the Checkpoint result without depending on TestResults Window

v_ChkPntStatus = Browser(…).Page(…).WebEdit(…).Check (Checkpoint(”CheckPointName1″))
Return Value is True if the checkpoint is passed otherwise its false.
if v_ChkPntStatus then
MsgBox “Check Point passed.”
else
MsgBox “Check Point failed.”
end if

ActiveX Data Objects

Microsoft's ActiveX Data Objects (ADO) is a set of Component Object Model (COM) objects for accessing data sources. It provides a layer between programming languages and OLE DB (a means of accessing data stores, whether they be databases or otherwise, in a uniform manner). ADO allows a developer to write programs that access data without knowing how the database is implemented. You must be aware of your database for connection only. No knowledge of SQL is required to access a database when using ADO, although one can use ADO to execute arbitrary SQL commands. The disadvantage of this (i.e. using SQL directly) is that it introduces a dependency upon the type of database used.

It is positioned as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects). ADO was introduced by Microsoft in October 1996.

ADO is made up of four collections and twelve objects:

ADO collections

Fields
This collection contains a set of Field objects. The Collection can be used in either a Recordset object or in a Record object. In a Recordset object, each of the Field objects that make up the Fields collection corresponds to a column in that Recordset object. In a Record object, a Field can be an absolute or relative URL that points into a tree-structured namespace (used for semi-structured data providers like the Microsoft OLE DB Provider for Internet Publishing) or as a reference to the default Stream object associated with that Record object.
Properties
An object can have more than one Property object, which are contained in the object's Properties collection.
Parameters
A Command object can have several Parameter commands to change its predefined behaviour, and each of the Parameter objects are contained in the Command object's Parameters collection
Errors
All provider created errors are passed to a collection of Error objects, while the Errors collection itself is contained in a Connection object. When an ADO operation creates an error, the collection is cleared and a new group of Error objects are created in the collection.

ADO objects

Connection
The connection object is ADO's connection to a data store via OLE DB. The connection object stores information about the session and provides methods of connecting to the data store. As some data stores have different methods of establishing a connection, some methods may not be supported in the connection object for particular OLE DB providers. A connection object connects to the data store using its 'Open' method with a connection string which specifies the connection as a list of key value pairs (for example: "Provider='SQLOLEDB';Data Source='TheSqlServer'; Initial Catalog='Northwind';Integrated Security='SSPI';"). The start of which must identify the type of data store connection that the connection object requires. This must be one of:
  • an OLE DB provider (for example SQLOLEDB), using the syntax "provider=";
  • a file name, using the syntax "file name=";
  • a remote provider and server (see RDS), using the syntax "Remote provider=" and "Remote server="; or
  • an absolute URL, using the syntax "URL="
Command
After the connection object establishes a session to the data source, instructions are sent to the data provider via the command object. The command object can send SQL queries directly to the provider through the use of the CommandText property, send a parameterised query or stored procedure through the use of a Parameter object or Parameters collection or run a query and return the results to a dataset object via the Execute method. There are several other methods that can be used in the Command object relating to other objects, such as the Stream, RecordSet or Connection objects.
Recordset
A recordset is a group of records, and can either come from a base table or as the result of a query to the table. The RecordSet object contains a Fields collection and a Properties collection. The Fields collection is a set of Field objects, which are the corresponding columns in the table. The Properties collection is a set of Property objects, which defines a particular functionality of an OLE DB provider. The RecordSet has numerous methods and properties for examining the data that exists within it. Records can be updated in the recordset by changing the values in the record and then calling on the Update or UpdateBatch method. Adding new records is performed through the AddNew function and then by calling on the Update or UpdateBatch method. Records are also deleted in the recordset with the Delete method and then by calling on the Update method. However, if for some reason the deletion cannot occur, such as because of violations in referential integrity, then the recordset will remain in edit mode after the call to the Update method. The programmer must explicitly call on the CancelUpdate function to cancel the update. Additionally, ADO can rollback transactions (if this is supported) and cancel batch updates. Recordsets can also be updated in one of three ways: via an immediate update, via a batch update, or through the use of transactions:
Immediate
The recordset is locked using the adLockOptimistic or adLockPessimistic lock. The data are updated at the data source after the record is changed and the Update method is called.
Batch
The recordset is locked using adLockBatchOptimistic and each time Update is called the data are updated in a temporary buffer. Finally, when UpdateBatch is called the data are completely updated back at the data source. This has the advantage of it all being done in memory, and if a problem occurs then UpdateCancel is called and the updates are not sent to the data source
Transaction
If the OLE DB provider allows it, transactions can be used. To start the transaction, the programmer invokes the BeginTrans method and does the required updates. When they are all done, the programmer invokes the CommitTrans method. RollbackTrans can be invoked to cancel any changes made inside the transaction and rollback the database to the state before the transaction began
Record
This object represents one record in the database, and contains a fields collection. A RecordSet consists of a collection of Record objects.
Stream
A stream, mainly used in a RecordSet object, is a means of reading and writing a stream of bytes. It is mostly used to save a recordset in an XML format, to send commands to an OLE DB provider as an alternative to the CommandText object and to contain the contents of a binary or text file.
Parameter
A parameter is a means of altering the behaviour of a common piece of functionality, for instance a stored procedure might have different parameters passed to it depending on what needs to be done; these are called parameterised commands.
Field
Each Record object contains many fields, and a RecordSet object has a corresponding Field object also. The RecordSet object's Field object corresponds to a column in the database table that it references.
Property
This object is specific to the OLE DB provider and defines an ability that the provider has implemented. A property object can be either a built-in property — it is a well defined property implemented by ADO already and thus cannot be altered — or can be a dynamic property — defined by the underlying data provider and can be changed
Error
When an OLE DB provider error occurs during the use of ADO, an Error object will be created in the Errors collection. Other errors do not go into an Error object, however. For instance, any errors that occur when manipulating data in a RecordSet or Field object are stored in a Status property.