Show / Hide Table of Contents

    IDataStore<TModel>.SetItem(int row, Expression<Func<TModel, object>> columnSelector, object value) Method

    .NET Standard 2.x

    Sets the value of a row and column (by column expression) to the specified value.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool SetItem(int row, Expression<Func<TModel, object>> columnSelector, object value);
    

    Parameters

    row System.Int32

    The zero-based row location in which you want to set the value.

    columnSelector System.Linq.Expressions.Expression<Func<TModel, object>>

    An expression used to specify the column.

    value System.Object

    The value to which you want to set the data at the row and column location. The datatype of the value must be the same as the datatype of the column.

    Returns

    System.Boolean

    Returns true if it succeeds.

    Examples

    The following code example uses the SetItem method to modify the value for the second column in the first row.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStore_GenericExamples
    {
        public class SetItemExample
        {
            private readonly SchoolContext _context;
    
            public SetItemExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore<D_Department>(_context);
    
                // Retrieves rows from the database for datastore
                datastore.Retrieve();
    
                Console.WriteLine("After Retrieve, Rowcount: {0}", datastore.RowCount);
    
                // Sets the value for the second column in the first row to "Engineering New"
                datastore.SetItem(0, a => a.Name, "Engineering New");
    
                Console.WriteLine("Gets the original value of name: {0}",
                    datastore.GetItem(0, a => a.Name, DwBuffer.Primary, true));
    
                Console.WriteLine("Gets the modified value of name: {0}",
                    datastore.GetItem(0, a => a.Name, DwBuffer.Primary, false));
    
                /*This code produces the following output:
                
                After Retrieve, Rowcount: 4   
                Gets the original value of name: Engineering
                Gets the modified value of name: Engineering New
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon