Show / Hide Table of Contents

    DataStoreExtensions.ImportRowFromJson(string json, int row, ref string error, DwBuffer dwbuffer = DwBuffer.Primary) Method

    .NET Standard 2.x

    Inserts a data row from a JSON string into a DataStore object.

    The JSON string that can be imported by this function must be a one-level plain JSON string.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

    public static int ImportRowFromJson(this IDataStoreBase dataStore, string json, int row, ref string error, DwBuffer dwbuffer = DwBuffer.Primary);
    

    Parameters

    json System.String

    A string specifying the JSON data. The JSON string must be in the plain format which must have only one level (cannot be two or more) and must be an object (cannot be an array).

    row System.Int32

    A long value identifying the row before which you want to insert a row. To insert a row at the end, specify a negative value, or a value greater than the row count in the DataStore buffer.

    error System.String

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

    DwBuffer DwNet.Data.DwBuffer

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

    Returns

    System.Int32

    Returns the amount of data rows that were inserted.

    Examples

    The following code example inserts a row of data from a JSON string into the DataStore primary buffer.

    using System;
    using DWNet.Data;
    using PowerScript.Bridge;
    using Appeon.ApiDoc.Models;
    using Newtonsoft.Json;
    
    namespace Appeon.ApiDoc.DataStoreExtensionsExamples
    {
        public class ImportRowFromJsonExample
        {
            private readonly SchoolContext _context;
    
            public ImportRowFromJsonExample(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");
    
                // Creates a new D_Department object and populates it with data.
                D_Department department = new D_Department
                {
                    Departmentid = 1,
                    Name = "Development",
                    Budget = 100,
                    Startdate = DateTime.Now,
                    Administrator = 1
                };
    
                // Serializes the model into JSON data.
                string json = JsonConvert.SerializeObject(department);
    
                string error = "";
                // Imports a row of data from JSON to DataStore primary buffer.
                int result = datastore.ImportRowFromJson(json, 0, ref error, DwBuffer.Primary);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
    
                /*This code produces the following output:
                
                Rowcount: 1           
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon