This example uses the Biblio.mdb file shipped with Microsoft Visual Basic. The TestProc
procedure connects to the database, processes the first ten records of the Authors table, then posts data into the test log.
Note: |
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
function TestProc()
{
var AConnection, RecSet, i;
// Create a Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create a connection using the following code:
// AConnection = getActiveXObject("ADODB.Connection");
// Specify the connection string
AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
// Open the connection
AConnection.Open();
// Return the Authors table
RecSet = AConnection.Execute("Authors", i, adCmdTable);
// Process the first ten records and post data to the test log
RecSet.MoveFirst();
for (let i = 1; i <= 10; i++)
{
Log.Message(RecSet.Fields.Items("Author").Value);
RecSet.MoveNext()
}
// Close the connection
AConnection.Close();
}
JScript
function TestProc()
{
var AConnection, RecSet, i;
// Create a Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create a connection using the
following code:
// AConnection = new ActiveXObject("ADODB.Connection");
// Specify the connection string
AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
// Open the connection
AConnection.Open();
// Return the Authors table
RecSet = AConnection.Execute("Authors", i, adCmdTable);
// Process the first ten records and post data to the test log
RecSet.MoveFirst();
for (i = 1; i <= 10; i++)
{
Log.Message(RecSet.Fields("Author").Value);
RecSet.MoveNext()
}
// Close the connection
AConnection.Close();
}
Python
def TestProc():
# Create a Connection object
AConnection = ADO.CreateConnection()
# Specify the connection string
AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb"
# Open the connection
AConnection.Open()
# Return the Authors table
RecSet = AConnection.Execute("Authors", i, adCmdTable)
# Process the first ten records and post data to the test log
RecSet.MoveFirst()
for i in range (1, 11):
Log.Message(str(RecSet.Fields.Items("Author").Value))
RecSet.MoveNext()
# Close the connection
AConnection.Close()
VBScript
Sub TestProc
' Create a Connection object
Set AConnection = ADO.CreateConnection
' Note that you can also create a connection using the
following code:
' Set AConnection = CreateObject("ADODB.Connection")
' Specify the connection string
AConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb"
' Open the database
AConnection.Open
' Return the Authors table
Set RecSet = AConnection.Execute("Authors", i, adCmdTable)
' Iterate through the records and
' post messages to the test log
RecSet.MoveFirst
For i = 1 To 10
Log.Message RecSet.Fields("Author").Value
RecSet.MoveNext
Next
' Close the connection
AConnection.Close
End Sub
DelphiScript
procedure TestProc;
var
AConnection, RecSet : OleVariant;
i : integer;
begin
// Create a new Connection object
AConnection := ADO.CreateADOConnection;
// Note that you can also create a connection using the
following code:
// AConnection := Sys.OleObject('ADODB.Connection');
// Specify the connection string
AConnection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb';
// Suppress the login dialog box
AConnection.LoginPrompt := False;
// Open the connection
AConnection.Open;
// Return the Authors table
RecSet := AConnection.Execute_('Authors', i, adCmdTable);
// Process the first ten records
RecSet.MoveFirst;
for i := 1 to 10 do
begin
Log.Message(RecSet.Fields('Author').Value);
RecSet.MoveNext;
end;
// Close the connection
AConnection.Close;
end;
C++Script, C#Script
function TestProc()
{
var AConnection, RecSet, i;
// Create a Connection object
AConnection = ADO["CreateConnection"]();
// Note that you can also create a connection using the
following code:
// AConnection = new ActiveXObject("ADODB.Connection");
// Specify the connection string
AConnection["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
// Open the connection
AConnection["Open"]();
// Return the Authors table
RecSet = AConnection["Execute"]("Authors", i, adCmdTable);
// Process the first ten records and post data to the test log
RecSet["MoveFirst"]();
for (i = 1; i <= 10; i++)
{
Log["Message"](RecSet["Fields"]("Author")["Value"]);
RecSet["MoveNext"]()
}
// Close the connection
AConnection["Close"]();
}