Show / Hide Table of Contents

    IDataStore.AddRow<TModel>(TModel model) Method

    .NET Standard 2.x

    Generic method. Appends a TModel object as a row to the end of the primary buffer in the DataStore and returns the index number.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public int AddRow<TModel>(TModel model);
    

    Type Parameters

    TModel

    The type of a model class that matches with the current DataObject.

    Parameters

    model TModel

    A TModel object that represents the row of data to add to the DataStore.

    Returns

    System.Int32

    Returns the zero-based index number of the row that was added.

    Remarks

    The status flag for the newly added row is ModelState.NewModified, and the row is included in the modified count.

    Examples

    The following code example demonstrates how to use the AddRow method to add a row of data to the DataStore.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class AddRowExample
        {
            private readonly SchoolContext _context;
    
            public AddRowExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example2()
            {
                // Instantiates a DataStore object with dataobject: d_department.
                var datastore = new DataStore("d_department", _context);
    
                Console.WriteLine("Before AddRow, Rowcount: {0}", datastore.Retrieve());
    
                // Creates a D_Department object.
                var department = new D_Department
                {
                    Departmentid = 20,
                    Name = "department name2",
                    Budget = 20,
                    Startdate = DateTime.Now,
                    Administrator = 2
                };
    
                // AddRow method returns the zero-based index number of the row that 
                // was added.
                int currentRow = datastore.AddRow(department);
    
                Console.WriteLine("AddRow return value: {0}", currentRow);
    
                // Commits changes to database
                datastore.Update();
    
                Console.WriteLine("After Update and Retrieve, Rowcount: {0}",
                    datastore.Retrieve());
    
                /*This code produces the following output:
                
                Before AddRow, Rowcount: 4
                AddRow return value: 4
                After Update and Retrieve, Rowcount: 5           
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon