TestComplete samples (both built-in and additional) are located in the <Users>\Public\Public Documents\TestComplete 14 Samples folder.
Some file managers display the Public Documents folder as Documents.
The following code illustrates how you can use the IAQAADOTable
object, based on the TADOTable class. The TestProc
routine accesses data in the table and posts them to the test log.
Notes:
-
This example uses the OrdersDB.mdb file that is part of the additional sample package. To use it, download this package from support.smartbear.com/downloads/testcomplete/samples/ and install it. After the installation is over, you can find the database in the <TestComplete 14 Samples>\Desktop\Checkpoints\XML\DataGridViewSample folder.
-
Using the Microsoft.Jet.OLEDB.4.0 provider requires that you run your script in the 32-bit version of TestComplete.
TestComplete 32-bit executable is located in the <TestComplete>\Bin folder.
JavaScript, JScript
function TestProc()
{
var Tbl;
// Create an IAQAADOTable object
Tbl = ADO.CreateADOTable();
// Specify the connection string
Tbl.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the table name
Tbl.TableName = "orders";
// Open the table
Tbl.Open();
// Process records and post data to the test log
Log.AppendFolder("Customers from Canada");
Tbl.First();
while( ! Tbl.EOF)
{
if (Tbl.FieldByName("state").Value == "Canada")
Log.Message(Tbl.FieldByName("name").Value);
Tbl.Next();
}
Tbl.Close();
}
Python
def TestProc():
# Create an IAQAADOTable object
Tbl = ADO.CreateADOTable()
# Specify the connection string
Tbl.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +\
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"
# Specify the table name
Tbl.TableName = "orders"
# Open the table
Tbl.Open()
# Process records and post data to the test log
Log.AppendFolder("Customers from Canada")
Tbl.First()
while not Tbl.EOF:
if (Tbl.FieldByName("state").Value == "Canada"):
Log.Message(Tbl.FieldByName("name").Value)
Tbl.Next()
Tbl.Close()
VBScript
Sub TestProc
' Create an IAQAADOTable object
Set Tbl = ADO.CreateADOTable
' Specify the connection string
Tbl.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"+_
"Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb"
' Specify the table name
Tbl.TableName = "orders"
' Open the table
Tbl.Open
' Process records and post data to the test log
Log.AppendFolder("Customers from Canada")
Tbl.First
While Not Tbl.EOF
If aqString.Format("%s", Tbl.FieldByName("state").Value) = "Canada" Then
Log.Message Tbl.FieldByName("name").Value
End If
Tbl.Next
WEnd
Tbl.Close
End Sub
DelphiScript
procedure TestProc;
var
Tbl : OleVariant;
begin
// Create an IAQAADOTable object
Tbl := ADO.CreateADOTable;
// Specify the connection string
Tbl.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb';
// Specify the table name
Tbl.TableName := 'orders';
// Open the table
Tbl.Open;
// Process records and post data to the test log
Log.AppendFolder('Customers from Canada');
Tbl.First;
while not Tbl.EOF do
begin
if (aqString.Format('%s',Tbl.FieldByName('state').Value) = 'Canada') then
Log.Message(Tbl.FieldByName('name').Value);
Tbl.Next;
end;
Tbl.Close;
end;
C++Script, C#Script
function TestProc()
{
var Tbl, i;
// Create an IAQAADOTable object
Tbl = ADO["CreateADOTable"]();
// Specify the connection string
Tbl["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the table name
Tbl["TableName"] = "orders";
// Open the table
Tbl["Open"]();
// Process records and post data to the test log
Log["AppendFolder"]("Customers from Canada");
Tbl["First"]();
while(! Tbl["EOF"])
{
if (Tbl["FieldByName"]("state")["Value"] == "Canada")
Log["Message"](Tbl["FieldByName"]("name")["Value"]);
Tbl["Next"]();
};
Tbl["Close"]();
}