ADO.CreateRecordset Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

This function creates a new ADO Recordset object and returns a reference to it. This object will allow you to work with all recordsets (tables, query results, etc.) from you scripts.

For detailed information on the Recordsetobject, see documentation on Microsoft ADO objects in the MSDN Library.

Declaration

ADO.CreateRecordset()

Result A Recordset object (Microsoft ADO)

Applies To

The method is applied to the following object:

Result Value

A Microsoft ADO Recordset object.

Remarks

Note that you can also create a new ADO Recordset object by its ProgID, ADODB.Recordset, using the Sys.OleObject routine or the getActiveXObject method (JavaScript only):

JavaScript

rs = getActiveXObject("ADODB.Recordset");

JScript

rs = Sys.OleObject("ADODB.Recordset");
// -- or --
rs = new ActiveXObject("ADODB.Recordset");

Python

rs = Sys.OleObject["ADODB.Recordset"]

VBScript

Set rs = Sys.OleObject("ADODB.Recordset")
' -- or --
Set rs = CreateObject("ADODB.Recordset")

DelphiScript

rs := Sys.OleObject['ADODB.Recordset'];

C++Script, C#Script

rs = Sys["OleObject"]("ADODB.Recordset");
// -- or --
rs = new ActiveXObject("ADODB.Recordset");

Example

The following example demonstrates how you can use the ADO Recordset object. The TestProc procedure connects to the database, creates the recordset and posts its data to the test log.

Notes:

JavaScript, JScript

function TestProc()
{
  // Create a new Connection object
  var Conn = ADO.CreateConnection();
  Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Users\\Public\\Documents\\TestComplete 15 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
  Conn.Open();
  // Create a new Recordset object
  var Rs = ADO.CreateRecordset();
  Rs.Open("orders", Conn, adOpenStatic, adLockReadOnly, adCmdTable);
  // Read data from the recordset and post them to the test log
  Log.AppendFolder("Customer names");
  Rs.MoveFirst();
  while(! Rs.EOF)
  {
    Log.Message(Rs.Fields.Item("name").Value);
    Rs.MoveNext();
  }
  // Close the recordset and connection
  Rs.Close();
  Conn.Close();
}

Python

def TestProc(): 
  # Create a new Connection object
  Conn = ADO.CreateConnection()
  Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
  "Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"
  Conn.Open()
  # Create a new Recordset object
  Rs = ADO.CreateRecordset()
  Rs.Open("orders", Conn, adOpenStatic, adLockReadOnly, adCmdTable)
  # Read data from the recordset and post them to the test log
  Log.AppendFolder("Customer names")
  Rs.MoveFirst()
  while not Rs.EOF:
    Log.Message(Rs.Fields.Item["name"].Value)
    Rs.MoveNext()    
  # Close the recordset and connection
  Rs.Close()
  Conn.Close()

VBScript

Sub TestProc
  Dim Conn, Rs
  ' Create a new Connection object
  Set Conn = ADO.CreateConnection
  Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
  "Data Source=C:\Users\Public\Documents\TestComplete 15 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb"
  Conn.Open
  ' Create a new Recordset object
  Set Rs = ADO.CreateRecordset
  Rs.Open "orders", Conn, adOpenStatic, adLockReadOnly, adCmdTable
  ' Read data from the recordset and post them to the test log
  Log.AppendFolder "Customer names"
  Rs.MoveFirst
  While Not Rs.EOF
    Log.Message Rs.Fields.Item("name").Value
    Rs.MoveNext
  WEnd
  ' Close the recordset and connection
  Rs.Close
  Conn.Close
End Sub

DelphiScript

procedure TestProc;
var
  Conn, Rs : OleVariant;
begin
   // Create a new Connection object
  Conn := ADO.CreateConnection;
  Conn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\Users\Public\Documents\TestComplete 15 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb';
  Conn.Open;
  // Create a new Recordset object
  Rs := ADO.CreateRecordset;
  Rs.Open('orders', Conn, adOpenStatic, adLockReadOnly, adCmdTable);
  // Read data from the recordset and post them to the test log
  Log.AppendFolder('Customer names');
  Rs.MoveFirst;
  while not Rs.EOF do
  begin
    Log.Message(Rs.Fields.Item('name').Value);
    Rs.MoveNext;
  end;
  // Close the recordset and connection
  Rs.Close;
  Conn.Close;
end;

C++Script, C#Script

function TestProc()
{
  // Create a new Connection object
  var Conn = ADO["CreateConnection"]();
  Conn["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=C:\\Users\\Public\\Documents\\TestComplete 15 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
  Conn["Open"]();
  // Create a new Recordset object
  var Rs = ADO["CreateRecordset"]();
  // Open the recordset and get the Orders table from the OrdersDB database
  Rs["Open"]("orders", Conn, adOpenStatic, adLockReadOnly,adCmdTable);
  // Read data from the recordset and post them to the test log
  Log["AppendFolder"]("Customer names");
  Rs["MoveFirst"]();
  while(! Rs["EOF"])
  {
    Log["Message"](Rs["Fields"]["Item"]("name")["Value"]);
    Rs["MoveNext"]();
  }
  // Close the recordset and connection
  Rs["Close"]();
  Conn["Close"]();
}

See Also

CreateADODataset Method
CreateCommand Method
CreateConnection Method

Highlight search results