Show / Hide Table of Contents

    IDataStoreBase.SetRowStatus(int row, DwBuffer bufferType, ModelState modelState) Method

    .NET Standard 2.x

    Sets the modification status of the specified row in the specified buffer in the DataStore. The row modification status determines the type of SQL statement the Update method will generate for the row.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool SetRowStatus(int row, DwBuffer bufferType, ModelState modelState);
    

    Parameters

    row System.Int32

    The zero-based index number of the row in which you want to set the status.

    dwbuffer DWNet.Data.DwBuffer

    A value identifying the DataWindow buffer that contains the row.

    status SnapObjects.Data.ModelState

    A value of the ModelState enumerated datatype specifying the new status.

    Returns

    System.Boolean

    Returns true if it succeeds.

    Remarks

    When data is retrieved

    When data is retrieved into a DataStore, all columns initially have a status of PropertyState.NotModified. After data has changed in a column in a particular row, such as through the SetItem method, the status for that column changes to PropertyState.Modified. Once the status for any column in a retrieved row changes to PropertyState.Modified, the row status also changes to ModelState.Modified.

    When rows are inserted

    When a row is inserted into a DataStore, it initially has a row status of ModelState.New, and all columns in that row initially have a status of PropertyState.NotModified. After data has changed in a column in the row, such as through the SetItem method, the column status changes to PropertyState.Modified. Once the status for any column in the inserted row changes to PropertyState.Modified, the row status changes to ModelState.NewModified.

    When a DataStore column has a default value, the column status does not change to PropertyState.Modified until the user makes at least one actual change to a column in that row.

    When Update is called

    A row's status flag determines what SQL command the Update method uses to update the database. INSERT or UPDATE is called, depending upon the following row statuses:

    Row status SQL statement generated
    ModelState.NewModified INSERT
    ModelState.Modified UPDATE

    A column is included in an UPDATE statement only if the following two conditions are met:

    • The column is on the updatable column list maintained by the DataWindow object.

    • The column has a status of PropertyState.Modified.

      The DataStore includes all columns in INSERT statements it generates.

    Examples

    The following code example calls the SetRowStatus method to modify data status.

    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreBaseExamples
    {
        public class SetRowStatusExample
        {
            private readonly SchoolContext _context;
    
            public SetRowStatusExample(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);
    
                datastore.Retrieve();
    
                Console.WriteLine("Before SetRowStatus: {0}", datastore.GetRowStatus(0));
                // Modifies the data in the first row.
                datastore.SetItem(0, 1, "New Engineering");
                Console.WriteLine("After SetItem: {0}", datastore.GetRowStatus(0));
    
                Console.WriteLine("Before SetRowStatus: {0}", datastore.GetRowStatus(1));
                // Modifies the data in the second row.
                datastore.SetRowStatus(1, DwBuffer.Primary, ModelState.Modified);
                Console.WriteLine("After SetRowStatus: {0}", datastore.GetRowStatus(1));
    
                /*This code produces the following output:
                
                Before SetRowStatus: NotTracked
                After SetItem: Modified
                Before SetRowStatus: NotTracked
                After SetItem: Modified
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon