TestComplete samples (both built-in and additional) are located in the <Users>\Public\Public Documents\TestComplete 14 Samples folder.
Some file managers display the Public Documents folder as Documents.
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 Recordset
object, 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:
-
This example uses the OrdersDB.mdb file that is part of the additional sample package. To use it, download this package from support.smartbear.com/downloads/testcomplete/samples/ and install it. After the installation is over, you can find the database in the <TestComplete 14 Samples>\Desktop\Checkpoints\XML\DataGridViewSample folder.
-
Using the Microsoft.Jet.OLEDB.4.0 provider requires that you run your script in the 32-bit version of TestComplete.
TestComplete 32-bit executable is located in the <TestComplete>\Bin folder.
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 14 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 14 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 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 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 14 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
ADO.CreateADODataset Method
ADO.CreateCommand Method
ADO.CreateConnection Method