ADO.CreateADODataset

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

The following code illustrates how you can use the IAQAADODataset objects in your scripts. This example uses the Biblio.mdb database shipped with Microsoft Visual Basic. The TestProc routine copies fields from the Publishers table to 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.

JavaScript, JScript

function TestProc()
{
  var DSet;
  // Create the new IAQAADODataset object
  DSet = ADO.CreateADODataset();
  // Specify the connection string
  DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
  // Specify the command type and text
  DSet.CommandType = cmdTable;
  DSet.CommandText = "Publishers";
  // Open the dataset
  DSet.Open();
  // Process records of the Publishers table
  DSet.First();
  while (! DSet.EOF)
  {
    // Insert data into the test log
    Log.Message(DSet.FieldByName("Name").Value, DSet.FieldByName("Address").Value);
    DSet.Next();
  };
  DSet.Close();
}

Python

def TestProc():
  # Create the new IAQAADODataset object
  DSet = ADO.CreateADODataset()
  # Specify the connection string
  DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb"
  # Specify the command type and text
  DSet.CommandType = cmdTable
  DSet.CommandText = "Publishers"
  # Open the dataset
  DSet.Open()
  # Process records of the Publishers table
  DSet.First()
  while not DSet.EOF:
    # Insert data into the test log
    Log.Message(DSet.FieldByName("Name").Value, DSet.FieldByName("Address").Value)
    DSet.Next()
  DSet.Close()

VBScript

Sub TestProc
  ' Create the new IAQAADODataset object
  Set DSet = ADO.CreateADODataset
  ' Specify the connection string
  DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
  "Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb"
  ' Specify the command type and text
  DSet.CommandType = cmdTable
  DSet.CommandText = "Publishers"
  ' Open the dataset
  DSet.Open
  ' Process records of the Publishers table
  DSet.First
  While Not DSet.EOF
    ' Insert data into the test log
    Log.Message DSet.FieldByName("Name").Value, DSet.FieldByName("Address").Value
    DSet.Next
  Wend
  DSet.Close
End Sub

DelphiScript

procedure TestProc;
var
  DSet : OleVariant;
begin
  // Create the new IAQAADODataset object
  DSet := ADO.CreateADODataset;
  // Specify the connection string
  DSet.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb';
  // Specify the command type and text
  DSet.CommandType := cmdTable;
  DSet.CommandText := 'Publishers';
  // Open the dataset
  DSet.Open;
  // Process records of the Publishers table
  DSet.First;
  while not aqConvert.VarToBool(DSet.EOF) do
  begin
    // Insert data into the test log
    Log.Message(DSet.FieldByName('Name').Value, DSet.FieldByName('Address').Value);
    DSet.Next;
  end;
  DSet.Close;
end;

C++Script, C#Script

function TestProc()
{
  var DSet;
  // Create the new IAQAADODataset object
  DSet = ADO["CreateADODataset"]();
  // Specify the connection string
  DSet["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Microsoft Visual Studio\\VB98\\BIBLIO.MDB";
  // Specify the command type and text
  DSet["CommandType"] = cmdTable;
  DSet["CommandText"] = "Publishers";
  // Open the dataset
  DSet["Open"]();
  // Process records of the Publishers table
  DSet["First"]();
  while (!DSet["EOF"])
  {
    // Insert data into the test log
    Log["Message"](DSet["FieldByName"]("Name")["Value"], DSet["FieldByName"]("Address")["Value"]);
    DSet["Next"]();
  };
  DSet["Close"]();
}

Highlight search results