ADO.CreateADODataset

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

The following code illustrates how you can use the IAQAADODataset object, based on the TADODataset class. The TestProc routine retrieves fields from the source database and posts them to the test log.

Notes:

JavaScript, JScript

function TestProc()
 {
   var DSet, name, cost, discount;
   // Create a new IAQAADODataset object
   DSet = ADO.CreateADODataset();
   // Specify the connection string
   DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
   "Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
   // Specify the command type and text
   DSet.CommandType = cmdTable;
   DSet.CommandText = "products";
   // Open the dataset
   DSet.Open();
   // Process records of the products table
   Log.AppendFolder("Products")
   DSet.First();
   while (! DSet.EOF)
   {
     // Insert data into the test log
     name = DSet.FieldByName("name").Value;
     cost = DSet.FieldByName("cost").Value;
     discount = DSet.FieldByName("discount").Value;
     Log.Message(name + " - " + "cost: " + cost + "$"+ ", " + "discount: " + discount + "%");
     DSet.Next();
   };
   DSet.Close();
 }

Python

def TestProc():
  # Create a new IAQAADODataset object
  DSet = ADO.CreateADODataset()
  # Specify the connection string
  DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
  "Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"
  # Specify the command type and text
  DSet.CommandType = cmdTable
  DSet.CommandText = "products"
  # Open the dataset
  DSet.Open()
  # Process records of the products table
  Log.AppendFolder("Products")
  DSet.First()
  while not DSet.EOF:
    # Insert data into the test log
    name = DSet.FieldByName("name").Value
    cost = DSet.FieldByName("cost").Value
    discount = DSet.FieldByName("discount").Value
    Log.Message("{name} - cost: {cost}$, discount: {discount}%".format(name=name, cost = cost, discount = discount))
    DSet.Next()
  DSet.Close()

VBScript

Sub TestProc
  ' Create a new IAQAADODataset object
  Set DSet = ADO.CreateADODataset
  ' Specify the connection string
  DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
  "Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb"
  ' Specify the command type and text
  DSet.CommandType = cmdTable
  DSet.CommandText = "products"
  ' Open the dataset
  DSet.Open
  ' Process records of the products table
  Log.AppendFolder("Products")
  DSet.First
  While Not DSet.EOF
    ' Insert data into the test log
      str = aqString.Format("%s - cost: %d$, discount: %d%%", DSet.FieldByName("name").Value, _
      DSet.FieldByName("cost").Value, DSet.FieldByName("discount").Value)
     Log.Message(str)
    DSet.Next
  Wend
  DSet.Close
End Sub

DelphiScript

procedure TestProc;
var DSet, str;
begin
  // Create a new IAQAADODataset object
  DSet := ADO.CreateADODataset;
  // Specify the connection string
  DSet.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb';
  // Specify the command type and text
  DSet.CommandType := cmdTable;
  DSet.CommandText := 'products';
  // Open the dataset
  DSet.Open;
  // Process records of the Products table
  Log.AppendFolder('Products');
  DSet.First;
  while not aqConvert.VarToBool(DSet.EOF) do
  begin
    // Insert data into the test log
    str := aqString.Format('%s - cost: %d$, discount: %d%%', DSet.FieldByName('name').Value, DSet.FieldByName('cost').Value, DSet.FieldByName('discount').Value);
    Log.Message(str);
    DSet.Next;
   end;
  DSet.Close;
end;

C++Script, C#Script

function TestProc()
  {
    var DSet, name, cost, discount;
    // Create a new IAQAADODataset object
    DSet = ADO["CreateADODataset"]();
    // Specify the connection string
    DSet["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
    // Specify the command type and text
    DSet["CommandType"] = cmdTable;
    DSet["CommandText"] = "products";
    // Open the dataset
    DSet["Open"]();
    // Process records of the products table
    Log["AppendFolder"]("Products");
    DSet["First"]();
    while (!DSet["EOF"])
    {
      // Insert data into the test log
      name = DSet["FieldByName"]("name")["Value"];
      cost = DSet["FieldByName"]("cost")["Value"];
      discount = DSet["FieldByName"]("discount")["Value"];
      Log["Message"](name + " - " + "cost: " + cost + "$" + ", " + "discount: " + discount + "%");
      DSet["Next"]();
    };
    DSet["Close"]();
  }

Highlight search results