Show / Hide Table of Contents

    DataStore.Create(IDwMeta dwMeta) Method

    .NET Standard 2.x

    Creates a DataStore object according to the IDwMeta object.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public static IDataStore Create(IDwMeta dwMeta);
    

    Parameters

    dwMeta DWNet.Data.IDwMeta

    An IDwMeta object.

    Returns

    DWNet.Data.IDataStore

    The new DataStore created based on the specified IDwMeta.

    Examples

    The following code example demonstrates how to create a DataStore using the DwMeta and then retrieve data from the database.

    using DWNet.Data;
    using PowerScript.Bridge;
    using System;
    using System.IO;
    
    namespace Appeon.ApiDoc.DataStoreExamples
    {
        public class CreateExample
        {
            private readonly SchoolContext _context;
    
            public CreateExample(SchoolContext dataContext)
            {
                // Set Data Context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Creates a DataStore from SQL dynamically.
                // Defines a SQL Select statement.
                string sql = "SELECT DepartmentId, Name FROM dbo.Department";
    
                // Creates a DwMeta object.
                var dwMeta = DwMeta.CreateFromSql(sql, _context);
    
                // Creates a DataStore from DwMeta.
                var ds1 = DataStore.Create(dwMeta);
                ds1.DataContext = _context;
    
                // Retrieves data
                int row = ds1.Retrieve();
                Console.WriteLine($"DS1 Retrieve Count = {row}");
    
    
                // Creates a DataStore from DW Syntax dynamically.
                // Gets the SRD syntax
                string path = "ExamplesClient.pbw/examplesclient.pbt/school.pbl/d_department.srd";
                var syntax = File.ReadAllText(path);
                // Creates a DataObject object using the SRD syntax
                var dataobject = new DataObject(syntax);
    
                // Creates a DataStore object using the DataObject object
                var ds2 = DataStore.Create(dataobject);
                ds2.DataContext = _context;
                // Retrieves data
                row = ds2.Retrieve();
                Console.WriteLine($"DS2 Retrieve Count = {row}");
    
                /*This code produces the following output:
                
                DS1 Retrieve Count = 4
                DS2 Retrieve Count = 4
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon