Query in One Category |
Scroll |
The TheQuery class allows you to define and execute a document query in one category. It is conceptually similar to an SQL query with the following correspondences:
TheQuery |
SQL |
SELECT |
|
FROM |
|
WHERE |
|
ORDER BY |
The Step By Step guide and the examples below illustrate how to define and execute a typical document query. If you wish to search in more than one category pleas see "Query in Multiple Categories". "Process Query Results" explains how to process and iterate the result of a TheQuery.
1 |
Connect to the Thereforeā¢ server (see "Server - Connect and Disconnect" for Details) |
2 |
Declare and initialize a new TheQuery. |
3 |
Set a Category and Load it from the server (Comparable to SQL's FROM clause). |
4 |
Select the fields (columns) to be included in the results (Comparable to SQL's SELECT clause). |
5 |
Optional. Get a list of valid condition operators. (You can use these for defining conditions in step 6.) |
6 |
Specify conditions for your query (Comparable to SQL's WHERE clause) |
7 |
Set fields to sort results by (Comparable to SQL's ORDER BY clause). |
8 |
Execute the query on the server. |
9 |
Optional. Display query definition and results in a MessageBox. |
Requirements and Assumptions: Category number 5 with a string field number 70, string fields named "Supplier" and "InvoiceNo" and a field (of arbitrary type) named "Info". At least one document in that category matching the search criteria. If these assumptions do not apply to your system or configuration please replace them with appropriate values when copying the code samples below. Visual Basic Imports Therefore.API '...
' 1. Connect to the Thereforeā¢ server Dim server As New TheServer server.Connect(TheClientType.CustomApplication)
' 2. Declare and initialize a new TheQuery Dim query As New TheQuery
' 3. Set a category query.Category.Load(5, server)
' 4. Add all visible fields except 'Info' query.SelectFields.AddAll() query.SelectFields.Remove("Info")
' Optional 5. Get the list of valid condition operators Dim operators As ITheReadOnlyStringList = query.ValidOperators Console.WriteLine(operators.ToString())
' 6. Define query conditions query.Conditions.Add(70, "1* or 3*") query.Conditions.Add("Supplier", "A*")
' 7. Sort results by InvoiceNo query.OrderByFields.Add("InvoiceNo")
' 8. Execute the query Dim results As TheQueryResult = query.Execute(server)
' Optional 9. Display Query definition and results in a MessageBox System.Windows.Forms.MessageBox.Show(query.ToString() _ + vbNewLine + results.ToString()) C# using Therefore.API; //...
// 1. Connect to the Thereforeā¢ server TheServer server = new TheServer(); server.Connect(TheClientType.CustomApplication);
// 2. Declare and initialize a new TheQuery TheQuery query = new TheQuery();
// 3. Set a category query.Category.Load(5, server);
// 4. Add all visible fields except "Info" query.SelectFields.AddAll(); query.SelectFields.Remove("Info");
// Optional 5. Get the list of valid condition operators ITheReadOnlyStringList operators = query.ValidOperators; Console.WriteLine(operators.ToString());
// 6. Define query conditions query.Conditions.Add(70, "1* or 3*"); // using the field number query.Conditions.Add("Supplier", "A*"); // using the column name
// 7. Sort results by InvoiceNo query.OrderByFields.Add("InvoiceNo");
// 8. Execute the query TheQueryResult results = query.Execute(server);
// Optional 9. Display Query definition and results in a MessageBox System.Windows.Forms.MessageBox.Show(query.ToString() + "\r\n" + results.ToString()); |