Show / Hide Table of Contents

    IDataStore.SetModel<TModel>(int row, TModel model) Method

    .NET Standard 2.x

    Sets the data of a TModel object to the specified row of the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public void SetModel<TModel>(int row, TModel model);
    

    Type Parameters

    TModel

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

    Parameters

    row System.Int32

    The zero-based number of the row where data will be set. This row must exist.

    model TModel

    The TModel instance which will be set to the specified row in the primary buffer of DataStore.

    Examples

    The following code example demonstrates how to use the SetModel method to add a new data record in the DataStore.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SetModelExample
        {
            private readonly SchoolContext _context;
    
            public SetModelExample(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);
    
                // Creates a D_Department object.
                var department = new D_Department
                {
                    Departmentid = 10,
                    Name = "New Department",
                    Budget = 280000,
                    Startdate = DateTime.Now,
                    Administrator = 2
                };
    
                // Adds an empty row to the end of datastore
                int row = datastore.AddRow();
    
                // Populates the new row with the D_Department object.
                datastore.SetModel(row, department);
    
                Console.WriteLine("The value of the name column in the new row: {0}",
                    datastore.GetItemString(row, "name"));
    
                // Commits changes to database
                datastore.Update();
    
                Console.WriteLine("After AddRow, Rowcount: {0}",
                    datastore.RowCount);
    
                /*This code produces the following output:
                
                After Retrieve, Rowcount: 4
                The value of the name column in the new row: New Department
                After AddRow, 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