ADO.CreateADODataset Method

Applies to TestComplete 14.93, last modified on September 16, 2021

Description

Creates a new IAQAADODataSet object and returns a reference to it. This object allows script to navigate through dataset records and read or set their fields.

Declaration

ADO.CreateADODataset()

Result An IAQAADODataset object

Applies To

The method is applied to the following object:

Result Value

An object of the IAQAADODataset type.

Remarks

The IAQAADODataSet object is an analogue of a Borland VCL TADODataSet object. Methods and properties are identical.

For detailed information on the underlying TADODataSet object, see VCL documentation on ADODB classes.

Example

The following code illustrates how you can use the IAQAADODataset objects in your scripts. The TestProc routine retrieves fields from the database’s table and posts them to the test log.

Notes:

JavaScript, JScript

function TestProc()
 {
   var DSet, name, cost, discount;
   // Create the 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 the 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 the 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 the 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 the 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"]();
  }

See Also

ADO.CreateRecordset
ADO.CreateADOTable
ADO.CreateADOQuery
ADO.CreateADOStoredProc

Highlight search results