Show / Hide Table of Contents

    IDataStoreBase.ReselectRowAsync(int row, CancellationToken cancellationToken) Method

    .NET Standard 2.x

    Asynchronously accesses the database to retrieve values for all columns that can be updated and refreshes all timestamp columns in a row in the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public Task<int> ReselectRowAsync(int row, CancellationToken cancellationToken)
    

    Parameters

    row System.Int32

    A zero-based index number of the row.

    cancellationToken CancellationToken

    A cancellation token that can be used by other objects or threads to receive notice of cancellation.

    Returns

    Task<int>

    Returns a task that represents the asynchronous operation.

    Remarks

    ReselectRowAsync is supported for SQL Select DataStore. Use ReselectRowAsync to discard values the user has changed and replace them with values from the database after an update fails (due to a concurrent access error, for example).

    Examples

    The following code example modifies the values for the first row and then calls the ReselectRowAsync asynchronous method to retrieve the original values for the first row from database again. It uses a CancellationTokenSource type parameter to make this operation cancelable.

    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 ReselectRowAsyncExample
        {
            private readonly SchoolContext _context;
            
            public ReselectRowAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public async Task<int> Example2(CancellationTokenSource cts)
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
                
                datastore.Retrieve();
                
                Console.WriteLine("Department ID: {0}; Department Name: {1}",
                                   datastore.GetItem<int>(0, "departmentid"),
                                   datastore.GetItem<string>(0, "name"));
                                   
                // Modified the values for the first row.
                datastore.SetItem(0, "departmentid", 10);
                datastore.SetItem(0, "name", "Department Name");
                
                Console.WriteLine("Department ID: {0}; Department Name: {1}",
                                   datastore.GetItem<int>(0, "departmentid"),
                                   datastore.GetItem<string>(0, "name"));
                                   
                int result = 0;
                
                try
                {
                    // Calls ReselectRowAsync to retrieve values for the first row from database again.
                    // It will send SQL commands to database. If a task has been cancelled, the call to
                    // the DataStore.ReselectRowAsync method throws an OperationCanceledException.
                    result = await datastore.ReselectRowAsync(0, cts.Token);
                    
                    Console.WriteLine("Department ID: {0}; Department Name: {1}",
                                   datastore.GetItem<int>(0, "departmentid"),
                                   datastore.GetItem<string>(0, "name"));
                }
                catch (OperationCanceledException e)
                {
                    // The operation was cancelled before completion.
                    Console.WriteLine(e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally 
                {
                    cts.Dispose();
                }
                
                return result;
                                   
                /*This code produces the following output:
                 
                    A task was canceled.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon