Show / Hide Table of Contents

    IDataStore.ImportJson(string json) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Inserts data from a JSON string into the DataStore.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

     public int ImportJson(string json);
    

    Parameters

    json System.String

    A string specifying the JSON data.

    The JSON string must comply with the plain-format JSON or DataWindow JSON.

    Returns

    System.Int32

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

    Remarks

    For simple-format JSON: It imports the JSON data to the primary buffer. For DataWindow JSON: It imports data from all of the buffers from the JSON string to the corresponding buffers and, if any, imports the data for DataWindowChild.

    Examples

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

    using PowerBuilder.Data;
    using System;
    using System.IO;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class ImportJsonExample
        {
            private SchoolContext _context;
    
            public ImportJsonExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates the datastore with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                // Gets the JSON file
                string path = Path.Combine(AppContext.BaseDirectory,
                                    @"Jsons\IDatastore\ImportJson1.json");
                string json = File.ReadAllText(path);
    
                // Imports data from JSON to DataStore
                datastore.ImportJson(json);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
    
                /*This code produces the following output:
    
                Rowcount: 2
               */
            }
        }
    }
    

    Example Refer To

    JSON File: ImportJson1

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon