Show / Hide Table of Contents

    DataStoreDataExtensions.ImportRowFromJson(this IDataStoreBase dataStore, string text, int row,DwBuffer dwBuffer = DwBuffer.Primary) Method

    .NET Standard 2.x

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

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public static int ImportRowFromJson(this IDataStoreBase dataStore, string text, int row, DwBuffer dwBuffer = DwBuffer.Primary);
    

    Parameters

    text 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

    An Int32 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 number of rows in DataStore.

    dwbuffer DWNet.Data.DwBuffer

    The specified buffer of the DataStore.

    Returns

    System.Int32

    Returns the number of rows that were imported if it succeeds.

    Examples

    The following code example demonstrates how to import the department data from a JSON string to the DataStore.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using Newtonsoft.Json;
    using System;
    
    namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
    {
        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", _context);
    
                Console.WriteLine("Before Import, Rowcount: {0}", datastore.RowCount);
    			
    			// Instantiates a Department object and populates it with data.
                var department = new D_Department
                {
                    Departmentid = 1,
                    Name = "Development",
                    Budget = 100,
                    Startdate = DateTime.Now,
                    Administrator = 1
                };
    
                // Serializes the model into a JSON string
                string json = JsonConvert.SerializeObject(department);
    
                // Imports data from JSON to DataStore
                datastore.ImportRowFromJson(json, 0, DwBuffer.Primary);
    
                Console.WriteLine("After Import, Rowcount: {0}", datastore.RowCount);
    
                /*This code produces the following output:
    
                Before Import, Rowcount: 0
                After Import, 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