Show / Hide Table of Contents

    IDataStore.AddRow() Method

    .NET Standard 2.x

    Appends an empty row to the end of the primary buffer in the DataStore and returns the index number. If any columns have default values, the row is initialized with these values.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public int AddRow();
    

    Returns

    System.Int32

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

    Remarks

    A newly inserted row (with a status flag of ModelState.New) is not included in the modified count until that row is populated with data (its status flag becomes NewModified!).

    Examples

    The following code example demonstrates how to use the AddRow method to add an empty row to the DataStore and then use SetItem to enter the data for the row.

    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 Example1()
            {
                // Instantiates a DataStore object with dataobject: d_department.
                var datastore = new DataStore("d_department", _context);
    
                Console.WriteLine("Before AddRow, Rowcount: {0}", datastore.Retrieve());
    
                // AddRow method returns the zero-based index number of the row that 
                // was added.
                int currentRow = datastore.AddRow();
    
                Console.WriteLine("AddRow return value: {0}", currentRow);
    
                datastore.SetItem(currentRow, "Departmentid", 10);
                datastore.SetItem(currentRow, "Name", "department name");
                datastore.SetItem(currentRow, "Budget", 20m);
                datastore.SetItem(currentRow, "Startdate", DateTime.Now);
                datastore.SetItem(currentRow, "Administrator", 2);
    
                // Commits data 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