DwTemplateImporter.Import(IDataStoreBase dataStore, IDataTemplate template, string data) Method
.NET Standard 2.x
Imports data to the DataStore
using DataTemplate
.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int Import(IDataStoreBase dataStore, IDataTemplate template, string data)
Parameters
dataStore
SnapObjects.Data.IDataStoreBase
The DataStore where you want to import data to.
template
SnapObjects.Data.IDataTemplate
A formatted data template for populating data.
data
System.String
Data string in the template format.
Returns
System.Int32
Returns the number of rows imported to the DataStore.
Examples
The following code example demonstrates how to use the Import
method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Appeon.ApiDoc.Models;
using DWNet.Data;
using SnapObjects.Data;
namespace Appeon.ApiDoc.DwTemplateImporterExamples
{
public class ImportExample
{
private readonly SchoolContext _context;
public ImportExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates datastore with datawindow: Dw_Book_DataTemplateImportData
var ds = new DataStore<Dw_Book_DataTemplateImportData>(_context);
var ds2 = new DataStore<Dw_Book_DataTemplateImportData>(_context);
ds.Retrieve();
// Get the template of the Dw_Book_DataTemplateImportData class.
var template = ds.GetTemplate("dw_book_json", DataFormat.Json);
// Exports data from the DataStore using DataTemplate.
var json = DwTemplateExporter.Export(ds, template);
// Import data to DataStore2.
int affected = DwTemplateImporter.Import(ds2, template, json);
Console.WriteLine("Affected rows: {0}", affected);
/*This code produces the following output:
Affected rows: 800
*/
}
}
}
Example Refer To
Model Class: D_Book_DataTemplateImportData