Show / Hide Table of Contents

    IDwDataImporter.Import(string text, DwBuffer dwbuffer, int startRow) Method

    .NET Standard 2.x

    Imports data into the DataStore specified buffer with the specified DataFormat, and specifies the start position of the row.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    int Import(string text, DwBuffer dwbuffer, int startRow);
    

    Parameters

    text System.String

    Data string in the specified format.

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

    dwbuffer DWNet.Data.DwBuffer

    The specified buffer of the DataStore.

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

    For plain-format JSON: Imports the JSON data to the specified buffer.

    For DataWindow JSON: Imports data from the specified buffer from the JSON string to the corresponding buffer.

    startRow System.Int32

    The zero-based index number of the first row in the buffer that you want to export.

    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 the starting row in a JSON string to the specified buffer.

    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    using System.IO;
    
    namespace Appeon.ApiDoc.IDwDataImporterExamples
    {
        public class ImportExample
        {
            private readonly SchoolContext _context;
    
            public ImportExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example5()
            {
                // Instantiates the datastore with datawindow: d_department
                var datastore = new DataStore("d_department", _context);
    
                // Get DataStore importer in JSON format.
                var importer = datastore.GetDataImporter(DataFormat.Json);
    
                // Gets the JSON file,ExportPlainJson1.json contains 4 records.
                string path = Path.Combine(AppContext.BaseDirectory,
                                    @"Jsons\IDwDataExporter\ExportPlainJson1.json");
                string json = File.ReadAllText(path);
    
                // Imports data from JSON to the DataStore primary buffer.
                // Imports from row 1.
                int row = importer.Import(json, DwBuffer.Primary, 0);
    
                Console.WriteLine("Import Row: {0}; Rowcount: {1}", row, datastore.RowCount);
    
                datastore.Reset();
    
                // Imports data from row 2 of the JSON string to the primary buffer.
                row = importer.Import(json, DwBuffer.Primary, 1);
    
                Console.WriteLine("Import Row: {0}; Rowcount: {1}", row, datastore.RowCount);
    
                /*This code produces the following output:
    
                Import Row: 4; Rowcount: 4
                Import Row: 3; Rowcount: 3
               */
            }
        }
    }
    

    Example Refer To

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

    Back to top Generated by Appeon