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
function TestProc()
{
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] >= :Param_Year";
// Specify the parameter value
Qry.Parameters.ParamByName("Param_Year").Value = 1950;
// 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] >= :Param_Year"
# Specify the parameter value
Qry.Parameters.ParamByName("Param_Year").Value = 1950
# 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
Sub TestProc
' 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] >= :Param_Year"
' Specify the parameter value
Qry.Parameters.ParamByName("Param_Year").Value = 1950
' 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
procedure TestProc;
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] >= :Param_Year';
// Specify the parameter value
Qry.Parameters.ParamByName['Param_Year'].Value := 1950;
// 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
function TestProc()
{
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] >= :Param_Year";
// Specify the parameter value
Qry["Parameters"]["ParamByName"]("Param_Year")["Value"] = 1950;
// 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"]();
}