DBTables Object

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The DBTables object provides scripting access to elements of the Stores | DBTables collection in your project.

The names of the DBTables objects coincide with the names of the child DBTable elements. Each property returns the DBTable object that corresponds to the appropriate child DBTable element. For instance, the following code provides access to the element named DBTable1:

JavaScript, JScript

var DBTableElem = DBTables.DBTable1;

Python

DBTableElem = DBTables.DBTable1

VBScript

Set DBTableElem = DBTables.DBTable1

DelphiScript

var
  DBTableElem : OleVariant;
begin
  DBTableElem := DBTables.DBTable1;
end;

C++Script, C#Script

var DBTableElem = DBTables["DBTable1"];

Using methods and properties of the DBTable object you can access the element’s properties from scripts and perform a comparison of the stored data against the database data. For more information, see Database Checkpoints.

Requirements

The object is available only if the project contains the Stores | DBTables collection.

Members

Example

The following example demonstrates how you can use the DBTables object to connect to a database and compare its content with stored data.

Notes:

  • This sample uses Jet OLE DB Provider 4.0 to connect to the database. If you use another version of Microsoft Jet, just replace the version number in the code.

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

JavaScript, JScript

function UsingDBTables()
{
  // Specifies a DB Table element
  var DBTab = DBTables.DBTable1;

  DBTab.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Work\\MyDB.mdb;";
  // Specifies the login and password
  DBTab.Login = "Tester";
  DBTab.Password = "123";

  // Specifies comparison parameters
  ReportDif = true;
  MessType = lmError;
  // Compares the DB Table element with data stored in a database
  DBTab.Compare(ReportDif, MessType);
}

Python

def UsingDBTables():
  # Specifies a DB Table element
  DBTab = DBTables.DBTable1;
  DBTab.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Work\\MyDB.mdb;";
  # Specifies the login and password 
  DBTab.Login = "Tester"
  DBTab.Password = "123"
  # Specifies comparison parameters
  ReportDif = True
  MessType = lmError
  # Compares the DB Table element with data stored in a database
  DBTab.Compare(ReportDif, MessType)

VBScript

Sub UsingDBTables
  
  ' Specifies a DB Table element
  Set DBTab = DBTables.DBTable1

  DBTab.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
  "Data Source=C:\Work\MyDB.mdb;"
  ' Specifies the login and password
  DBTab.Login = "Tester"
  DBTab.Password = "123"

  ' Specifies comparison parameters
  ReportDif = True
  MessType = lmError
  ' Compares the DB Table element with data stored in a database
  Call DBTab.Compare(ReportDif, MessType)
   
End Sub

DelphiScript

procedure UsingDBTables();
var DBTab, MessType : variant;
var ReportDif : boolean;

begin
  
  // Specifies a DB Table element
  DBTab := DBTables.DBTable1;

  DBTab.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\Work\MyDB.mdb;';
  // Specifies the login and password
  DBTab.Login := 'Tester';
  DBTab.Password := '123';

  // Specifies comparison parameters
  ReportDif := true;
  MessType := lmError;
  
  // Compares the DB Table element with data stored in a database
  DBTab.Compare(ReportDif, MessType);
end;

C++Script, C#Script

function UsingDBTables()
{
  // Specifies a DB Table element
  var DBTab = DBTables["DBTable1"];

  DBTab["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Work\\MyDB.mdb;";
  // Specifies the login and password
  DBTab["Login"] = "Tester";
  DBTab["Password"] = "123";

  // Specifies comparison parameters
  ReportDif = true;
  MessType = lmError;
  // Compares the DB Table element with data stored in a database
  DBTab["Compare"](ReportDif, MessType);
}

See Also

About Database Checkpoints
About DBTables Collection
DBTable Object

Highlight search results