Show / Hide Table of Contents

    IDataStoreBase.RetrieveAsync(params object[] arguments) Method

    .NET Standard 2.x

    Asynchronously retrieves rows from the database. If arguments are included, the argument values are used for the retrieval arguments in the SQL SELECT statement for the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public Task<int> RetrieveAsync(params object[] arguments)
    

    Pararmeters

    arguments System.Object[]

    (Optional) One or more values that you want to use as retrieval arguments in the SQL SELECT statement defined in the DataStore.

    Returns

    Task<int>

    Returns a task that represents the asynchronous operation.

    Remarks

    After rows are retrieved, the DataStore's filter is applied. Therefore, any retrieved rows that do not meet the filter criteria are immediately moved to the filter buffer and are not included in the return count.

    Before you can retrieve rows for the DataStore, you must specify a DataContext object with the constructor of DataStore or SetDataContext method to establish a database connection.

    Normally, when you call the RetrieveAsync method, any rows that are already in the DataStore are discarded and replaced with the retrieved rows. You can set DwRetrieveEventArgs.IsResetBuffer to false in the RetrieveStart event to prevent this. In this case, RetrieveAsync adds any retrieved rows to the ones that already exist in the buffers.

    Events

    The RetrieveAsync method triggers these events: RetrieveStart and RetrieveEnd.

    None of these events is triggered if the data source is external, because RetrieveAsync always fails. You must use one of the import methods to populate the DataStore.

    Examples

    The following code example retrieves data asynchronously from the database.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using DWNet.Data;
    
    namespace Appeon.ApiDoc.IDataStoreBaseExamples
    {
        public class RetrieveAsyncExample
        {
            private readonly SchoolContext _context;
            
            public RetrieveAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public async Task<int> Example1()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
                
                int result = 0;
                
                try 
                {
                    // Retrieves rows from the database for datastore
                    // If a task has been cancelled, the call to the 
                    // DataStore.UpdateAsync method throws an OperationCanceledException.
                    result = await datastore.RetrieveAsync(2);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                
                Console.WriteLine("After Retrieve, Rowcount: {0}",
                        datastore.RowCount);
                        
                return result;
                
                /*This code produces the following output:
                
                    After Retrieve, Rowcount: 4
                */
                
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon