DBTableVariable Object

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

The DBTableVariable object provides a scripting interface for project, project suite and keyword test variables of the DB Table type. These variables simplify access to data stored outside of your TestComplete project in databases, Excel sheets or CSV files. The object implements the iterator functionality. It contains specific methods that let you go through data rows and access column values of the current row.

Members

Example

The code below obtains the total number of columns stored in the DBVar1 variable and then posts the names of these columns to the test log.

JavaScript, JScript

function DBTableVar()
{
  // Obtains a DB Table variable
  var DBTab = Project.Variables.DBVar1;
  // Initializes the iterator
  DBTab.Reset;
  // Obtains the total number of the table's columns
  var ColNum = DBTab.ColumnCount;
  
  // Iterates through the table's columns
  for (var i = 0; i < ColNum; i++)
  {
    var ColName = DBTab.ColumnName(i);
    Log.Message("The name of column " + (i+1) + " is: " + ColName);
  }
}

Python

def DBTableVar():
  # Obtains a DB Table variable
  DBTab = Project.Variables.DBVar1
  # Initializes the iterator
  DBTab.Reset()
  # Obtains the total number of the table's columns
  ColNum = DBTab.ColumnCount
  # Iterates through the table's columns
  for i in range(0, ColNum):
    ColName = DBTab.ColumnName[i]
    Log.Message("The name of column " + str(i + 1) + " is: " + ColName)

VBScript

Sub DBTableVar

  ' Obtains a DB Table variable
  Set DBTab = Project.Variables.DBVar1
  ' Initializes the iterator
  DBTab.Reset
  ' Obtains the total number of the table's columns
  ColNum = DBTab.ColumnCount
  
  ' Iterates through the table's columns
  For i = 0 to (ColNum - 1)
    ColName = DBTab.ColumnName(i)
    Log.Message("The name of column " & (i+1) & " is: " & ColName)
  Next

End Sub

DelphiScript

function DBTableVar;
var DBTab, ColNum, i, ColName;
begin

  // Obtains a DB Table variable
  DBTab := Project.Variables.DBVar1;
  // Initialize the iterator
  DBTab.Reset;
  // Obtains the total number of the table's columns
  ColNum := DBTab.ColumnCount;
  
  // Iterates through the table's columns
  for i := 0 to (ColNum - 1) do
  begin
    ColName := DBTab.ColumnName[i];
    Log.Message('The name of column ' + (i+1) + ' is: ' + ColName);
  end;

end;

C++Script, C#Script

function DBTableVar()
{
  // Obtains a DB Table variable
  var DBTab = Project["Variables"]["DBVar1"];
  // Initialize the iterator
  DBTab["Reset"];
  // Obtains the total number of the table's columns
  var ColNum = DBTab["ColumnCount"];
  
  // Iterates through the table's columns
  for (var i = 0; i < ColNum; i++)
  {
    var ColName = DBTab["ColumnName"](i);
    Log["Message"]("The name of column " + (i+1) + " is: " + ColName);
  }
}

See Also

Variables of the DB Table Type

Highlight search results