ColumnName Property

Applies to TestComplete 14.0, last modified on January 23, 2019

Description

Project, project suite and keyword test variables of the DB Table type store links to data storages. The ColumnName property returns the name of a column belonging to the data storage DBTableVariableObj provides access to.

Declaration

DBTableVariableObj.ColumnName(ColumnIndex)

Read-Only Property Integer
DBTableVariableObj An expression, variable or parameter that specifies a reference to a DBTableVariable object
ColumnIndex [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

ColumnIndex

Specifies the index of the column whose name you want to obtain. The index is zero-based, that is, the first column has index 0, the second -  1, the third -  2, and so on. The total number of columns is specified by the ColumnCount property.

If the specified column does not exist, an error occurs.

Property Value

A string which is the name of the specified column.

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