Description
Creates a new IAQAADOQuery object and returns a reference to it.
Declaration
ADO.CreateADOQuery()
| Result | An IAQAADOQuery object |
|||
Applies To
The method is applied to the following object:
Result Value
An object of the IAQAADOQuery type.
Remarks
The IAQAADOQuery object is an analogue of a Borland VCL TADOQuery object. Methods and properties are identical.
For detailed information on the underlying TADOQuery object, see VCL documentation on ADODB classes.
Once the IAQAADOQuery object is created, you can use it to send queries to databases. To do this:
- Establish a connection to the database (set the
ConnectionorConnectionStringproperty). - Specify the SQL expression (set the
SQLproperty). - If necessary, specify the query parameters (set the
Parametersproperty). - Run the query using the
OpenorExecSQLmethods.
Example
The following code illustrates how you can use the IAQAADOQuery object to retrieve data from the databases. This example uses the Biblio.mdb file shipped with Microsoft Visual Basic. The TestProc routine executes the query and inserts results into 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. TestComplete 32-bit executable is located in the <TestComplete>\Bin folder. |
JavaScript, JScript
{
var Qry;
// Create a query
Qry = ADO.CreateADOQuery();
// Specify the connection string
Qry.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
// Specify the SQL expression
Qry.SQL = "Select * FROM Authors WHERE Authors.[Year Born] <> 0";
// Execute the query
Qry.Open();
// Process results and insert data into the test log
Qry.First();
while (! Qry.EOF)
{
Log.Message(Qry.FieldByName("Author").Value, Qry.FieldByName("Year Born").Value);
Qry.Next();
}
// Closes the query
Qry.Close();
}
Python
def TestProc():
# Create a query
Qry = ADO.CreateADOQuery()
# Specify the connection string
Qry.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb"
# Specify the SQL expression
Qry.SQL = "Select * FROM Authors WHERE Authors.[Year Born] <> 0"
# Execute the query
Qry.Open()
# Process results and insert data into the test log
Qry.First()
while not Qry.EOF:
Log.Message(Qry.FieldByName("Author").Value, Qry.FieldByName("Year Born").Value)
Qry.Next()
# Closes the query
Qry.Close()
VBScript
' Create a query
Set Qry = ADO.CreateADOQuery
' Specify the connection string
Qry.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb"
' Specify the SQL expression
Qry.SQL = "Select * FROM Authors WHERE Authors.[Year Born] <> 0"
' Execute the query
Qry.Open
' Process results and insert data into the test log
Qry.First
While Not Qry.EOF
Log.Message Qry.FieldByName("Author").Value, Qry.FieldByName("Year Born").Value
Qry.Next
Wend
' Closes the query
Qry.Close
End Sub
DelphiScript
var
Qry : OleVariant;
begin
// Create a query
Qry := ADO.CreateADOQuery();
// Specify the connection string
Qry.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=C:\Microsoft Visual Studio\VB98\biblio.mdb';
// Specify the SQL expression
Qry.SQL := 'Select * FROM Authors WHERE Authors.[Year Born] <> 0';
// Execute the query
Qry.Open;
// Process results and insert data into the test log
Qry.First;
while not aqConvert.VarToBool(Qry.EOF) do
begin
Log.Message(Qry.FieldByName('Author').Value, Qry.FieldByName('Year Born').Value);
Qry.Next;
end;
// Closes the query
Qry.Close
end;
C++Script, C#Script
{
var Qry;
// Create a query
Qry = ADO["CreateADOQuery"]();
// Specify the connection string
Qry["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Microsoft Visual Studio\\VB98\\biblio.mdb";
// Specify the SQL expression
Qry["SQL"] = "Select * FROM Authors WHERE Authors.[Year Born] <> 0";
// Execute the query
Qry["Open"]();
// Process results and insert data into the test log
Qry["First"]();
while (!Qry["EOF"])
{
Log["Message"](Qry["FieldByName"]("Author")["Value"], Qry["FieldByName"]("Year Born")["Value"]);
Qry["Next"]();
}
// Closes the query
Qry["Close"]();
}
See Also
ADO.CreateADOTable
ADO.CreateADODataset
ADO.CreateADOStoredProc
