Show / Hide Table of Contents

    DataStoreExtensions.ImportJsonByKey(string json, ref string error, DwBuffer dwbuffer = DwBuffer.Primary, int startRow = 0, int endRow = -1) Method

    .NET Standard 2.x

    Inserts data from a JSON string into a DataStore object according to the key name of the JSON item.

    The JSON string must be a DataWindow JSON or a plain JSON.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

    public static int ImportJsonByKey(this IDataStoreBase dataStore, string json, ref string error, DwBuffer dwbuffer = DwBuffer.Primary, int startRow = 0, int endRow = -1);
    

    Parameters

    json System.String

    A string specifying the JSON data. The JSON string must be a DataWindow JSON or a plain JSON.

    error System.String

    A variable into which the returned warning or error message will be placed.

    bufferType DwNet.Data.DwBuffer

    A value of the DwBuffer enumerated datatype identifying the DataStore buffer from which you want to import the data. The default is DwBuffer.Primary.

    startRow System.Int32

    The number of the first detail object in the JSON array that you want to import. The default is 0. If it is negative, 0 is used.

    endRow System.Int32

    The number of the last detail object in the JSON array that you want to import. The default is the rest of the objects. If it is negative, it indicates the rest of rows.

    Returns

    System.Int32

    Returns the number of rows that were imported if it succeeds and returns a negative value if an error occurs.

    Examples

    The following code example imports data of the first and second rows from a JSON string into the DataStore primary buffer according to the key name of the JSON item.

    using System;
    using System.IO;
    using DWNet.Data;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.DataStoreExtensionsExamples
    {
        public class ImportJsonByKeyExample
        {
            private readonly SchoolContext _context;
    
            public ImportJsonByKeyExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates the datastore with datawindow: d_department.
                var datastore = new DataStore("d_department");
    
                // Gets the JSON file
                string path = "Jsons/DataStoreExtensions/ImportJson.json";
                string error = "";
                string json = File.ReadAllText(path);
    
                // Imports data from JSON to DataStore
                datastore.ImportJsonByKey(json, ref error, DwBuffer.Primary, 0, 1);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
    
                /*This code produces the following output:
    
                Rowcount: 2
               */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    JSON File: ImportJson
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon