Show / Hide Table of Contents

    IDataStore.GetModelByRowId<TModel>(int rowid) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Gets the TModel object of a row according to the unique row identifier associated with that row.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

     TModel GetRowByRowId<TModel>(int rowid);
    

    Type Parameters

    TModel

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

    Parameters

    rowid System.Int32

    A number specifying the row identifier for which you want to get the associated TModel object.

    Returns

    TModel

    Returns the TModel object of the row in the buffer. Returns null if no row is found.

    Remarks

    This method allows you to use a unique row identifier to retrieve the TModel object associated with that row. The row identifier is not affected by operations (such as Insert, Delete, or Filter) that might change the original order (and consequently the TModel object) of the rows in the DataStore.

    The row identifier is relative to the DataStore that currently owns the row.

    Examples

    The following code example demonstrates how to get row according to the unique row identifier.

    using PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class GetModelByRowIdExample
        {
            private SchoolContext _context;
    
            public GetModelByRowIdExample(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();
    
                datastore.SetSort("departmentid desc");
                datastore.Sort();
    
                var department = datastore.GetModel<D_Department>(0);
    
                Console.WriteLine(
                    "Row = 0, Department ID: {0}; Department Name: {1}",
                    department.Departmentid,
                    department.Name);
    
                department = datastore.GetModelByRowId<D_Department>(0);
    
                Console.WriteLine(
                    "Rowid = 0, Department ID: {0}; Department Name: {1}",
                    department.Departmentid,
                    department.Name);
    
                /*This code produces the following output:
                 
                Row = 0, Department ID: 7; Department Name: Mathematics
                Rowid = 0, Department ID: 1; Department Name: Engineering
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon