IDwDataImporter.ImportByKey(string text) Method
.NET Standard 2.x
Imports data into the DataStore buffer with the specified DataFormat
based on the key name.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
int ImportByKey(string text);
text
System.String
Data string in the specified format.
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.
Examples
The following code example demonstrates how to import the department data from a JSON string to the DataStore.
using DWNet.Data;
using SnapObjects.Data;
using System;
using System.IO;
namespace Appeon.ApiDoc.IDwDataImporterExamples
{
public class ImportByKeyExample
{
private readonly SchoolContext _context;
public ImportByKeyExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
// Instantiates a DataStore object 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 DataStore
int row = importer.ImportByKey(json);
Console.WriteLine("Import Row: {0}; Rowcount: {1}", row, datastore.RowCount);
/*This code produces the following output:
Import Row: 4; Rowcount: 4
*/
}
}
}
Example Refer To
Model Class: D_Department
JSON File: ExportPlainJson1
DataWindow File: d_department