Show / Hide Table of Contents

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

    .NET Standard 2.x

    Inserts data from a JSON string into a DataStore object.

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

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

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

    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.

    startColumn System.Int32

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

    endColumn System.Int32

    The number of the last key value in the JSON object that you want to import. The default is the rest of the key values. If it is negative, it indicates the rest of columns.

    dwStartColumn System.Int32

    The number of the first column in the DataStore that should receive data. The default is 0. If it is negative, 0 is used.

    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 columns in the first and second rows from a JSON string into the DataStore primary buffer starting from the first column.

    using System;
    using System.IO;
    using DWNet.Data;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.DataStoreExtensionsExamples
    {
        public class ImportJsonExample
        {
            private readonly SchoolContext _context;
    
            public ImportJsonExample(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.ImportJson(json, ref error, DwBuffer.Primary, 0, 1, 0, 1, 0);
    
                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