Show / Hide Table of Contents

    IDataStore.CopyTo(TModel[] array, int arrayIndex) Method

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

    0.5.0-alpha

    1.0.1 (current)

    Copies all rows from the primary buffer of the DataStore to a compatible one-dimensional array, starting at the specified array index.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public void CopyTo(TModel[] array, int arrayIndex);
    

    Parameters

    array TModel

    The one-dimensional array which is the destination for the rows copied from the primary buffer of the DataStore.

    arrayIndex System.Int32

    The zero-based index in array at which copying begins.

    Examples

    The following code example demonstrates how to use the CopyTo method.

    using PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class CopyToExample
        {
            private SchoolContext _context;
    
            public CopyToExample(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);
    
                // This datastore has 4 records
                datastore.Retrieve();
    
                D_Department[] departments = new D_Department[5];
    
                // Creates a D_Department object and populates it with data.
                var department = new D_Department();
                department.Departmentid = 20;
                department.Name = "New Department";
                department.Budget = 20;
                department.Startdate = DateTime.Now;
                department.Administrator = 2;
    
                // Sets the first element of the departments array.
                departments[0] = department;
    
                // Copies 4 records to the departments array. 
                // It starts at the index 1 of the array, so the first element (index = 0) 
                // in the departments array will not be affected.
                datastore.CopyTo(departments, 1);
               
                foreach( var d in departments)
                { 
                    Console.WriteLine("Department Name: {0}", d.Name);
                }
    
                /*This code produces the following output:
                
                Department Name: New Department
                Department Name: Engineering
                Department Name: English
                Department Name: Economics
                Department Name: Mathematics    
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon