ADO.CreateADOTable

Applies to TestComplete 12.60, last modified on September 17, 2018

The following code illustrates how you can use the IAQAADOTable object in your scripts. This example uses the Biblio.mdb file shipped with Microsoft Visual Basic. The TestProc routine iterates through the records of the Authors table and posts names of authors, to the test log, whose birth year is specified in the database.

Note:

Using the Microsoft.Jet.OLEDB.4.0 provider requires that you run your script in the 32-bit version of TestComplete.

JavaScript

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:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Specify the table name
  Tbl.TableName = "Authors";
  // Open the table
  Tbl.Open();
  // Process records and post data to the test log
  Tbl.First();
  while( ! Tbl.EOF)
  {
    if (!strictEqual(Tbl.FieldByName("Year Born").Value, null))
      Log.Message(aqConvert.VarToStr(Tbl.FieldByName("Year Born").Value) + " - " + Tbl.FieldByName("Author").Value);
    Tbl.Next();
  }
  Tbl.Close();
}

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:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Specify the table name
  Tbl.TableName = "Authors";
  // Open the table
  Tbl.Open();
  // Process records and post data to the test log
  Tbl.First();
  while( ! Tbl.EOF)
  {
    if (Tbl.FieldByName("Year Born").Value != null)
      Log.Message(aqConvert.VarToStr(Tbl.FieldByName("Year Born").Value) + " - " + Tbl.FieldByName("Author").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:\\Microsoft Visual Studio\\VB98\\biblio.mdb"
  # Specify the table name
  Tbl.TableName = "Authors"
  # Open the table
  Tbl.Open()
  # Process records and post data to the test log
  Tbl.First()
  while not Tbl.EOF:
    if (Tbl.FieldByName("Year Born").Value != None):
      Log.Message(aqConvert.VarToStr(Tbl.FieldByName("Year Born").Value) + " - " + Tbl.FieldByName("Author").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:\Microsoft Visual Studio\VB98\biblio.mdb"
  ' Specify the table name
  Tbl.TableName = "Authors"
  ' Open the table
  Tbl.Open
  ' Process records and post data to the test log
  Tbl.First
  While Not Tbl.EOF
    If Tbl.FieldByName("Year Born").Value <> 0 Then
      Log.Message CStr(Tbl.FieldByName("Year Born").Value) + " - " + Tbl.FieldByName("Author").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:\Microsoft Visual Studio\VB98\biblio.mdb';
  // Specify the table name
  Tbl.TableName := 'Authors';
  // Open the table
  Tbl.Open;
  // Process records and post data to the test log
  Tbl.First;
  while not Tbl.EOF do
  begin
    if (Tbl.FieldByName('Year Born').Value <> nil) then
      Log.Message(aqConvert.VarToStr(Tbl.FieldByName('Year Born').Value) + ' - ' + Tbl.FieldByName('Author').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:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Specify the table name
  Tbl["TableName"] = "Authors";
  // Open the table
  Tbl["Open"]();
  // Process the first ten records and post data to the test log
  Tbl["First"]();
  while(! Tbl["EOF"])
  {
    if (Tbl["FieldByName"]("Year Born")["Value"] != null)
      Log["Message"](aqConvert["VarToStr"](Tbl["FieldByName"]("Year Born")["Value"]) + " - " + Tbl["FieldByName"]("Author")["Value"]);
    Tbl["Next"]();
  };
  // Close the table
  Tbl["Close"]();
}

Highlight search results