IDwDataImporter.Import(string text, DwBuffer dwbuffer, int startRow, int endRow, int startColumn, int endColumn, int dwStartColumn) Method
.NET Standard 2.x
Imports data into the DataStore specified buffer with the specified DataFormat
, and specifies the start and end positions of the rows and columns, and specifies the start position of the DataWindowChild
column.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
int Import(string text, DwBuffer dwbuffer, int startRow, int endRow, int startColumn, int endColumn, int dwStartColumn);
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.
endRow
System.Int32
The zero-based index number of the last row in the buffer that you want to export.
If it is negative, it indicates the rest of rows.
startColumn
System.Int32
The zero-based index number of the first column in the buffer that you want to export.
endColumn
System.Int32
The zero-based index number of the last column in the buffer that you want to export.
dwStartColumn
System.Int32
specify the number of the first column in the DataStore that should receive data.
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 between the starting row and the ending row and from between the starting column and the ending column in a JSON string to the specified buffer beginning in the specified column.
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 Example9()
{
// 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 row 1 through the end
// Imports data from column 2 through the end. Column 1 will not be imported.
// DataStore receives data beginning in column 2, so DataStore column 1 has no data.
int row = importer.Import(json, DwBuffer.Primary, 0, 3, 1, 10, 1);
Console.WriteLine("Import Row: {0}; Rowcount: {1}", row, datastore.RowCount);
for (int i = 0; i < datastore.RowCount; i++)
{
Console.WriteLine("Department ID: {0}; Name: {1}",
datastore.GetItem<int>(i, "departmentid"),
datastore.GetItem<string>(i, "name"));
}
datastore.Reset();
// Imports data from row 2 and 3.
// Imports data starting from column 2. So column 1 will not be imported.
// Imports data starting from column 2 and imports only one column.
// DataStore receives data beginning in column 2, so DataStore column 1
// has no data.
row = importer.Import(json, DwBuffer.Primary, 1, 2, 1, 1, 1);
Console.WriteLine("Import Row: {0}; Rowcount: {1}", row, datastore.RowCount);
for (int i = 0; i < datastore.RowCount; i++)
{
Console.WriteLine("Department ID: {0}; Name: {1}",
datastore.GetItem<int>(i, "departmentid"),
datastore.GetItem<string>(i, "name"));
}
/*This code produces the following output:
Import Row: 4; Rowcount: 4
Department ID: 0; Name: Engineering
Department ID: 0; Name: English
Department ID: 0; Name: Economics
Department ID: 0; Name: Mathematics
Import Row: 2; Rowcount: 2
Department ID: 0; Name: English
Department ID: 0; Name: Economics
*/
}
}
}
Example Refer To
Model Class: D_Department
JSON File: ExportPlainJson1
DataWindow File: d_department