DataStoreDataExtensions.ImportRowFromXml(this IDataStoreBase dataStore, string text, int row,DwBuffer dwBuffer = DwBuffer.Primary) Method
.NET Standard 2.x
Inserts a data row from an XML string into a DataStore object.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int ImportRowFromXml(this IDataStoreBase dataStore, string text, int row, DwBuffer dwBuffer = DwBuffer.Primary);
Parameters
text
System.String
An XML string from which you want to copy the data.
row
System.Int32
An Int32 value identifying the row before which you want to insert a row. To insert a row at the end, specify a negative value or a value greater than the number of rows in DataStore.
dwbuffer
DWNet.Data.DwBuffer
The specified buffer of the DataStore.
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 an XML string to the DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ImportRowFromXmlExample
{
private readonly SchoolContext _context;
public ImportRowFromXmlExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
// Instantiates a Department object and populates it with data.
var department = new D_Department
{
Departmentid = 1,
Name = "Development",
Budget = 100,
Startdate = DateTime.Now,
Administrator = 1
};
// Adds the Department object to the DataStore.
datastore.Add(department);
Console.WriteLine("Before Import, Rowcount: {0}", datastore.RowCount);
// DataStore has only one row of data.
// Exports using the ExportPlainXml method.
string xml = datastore.ExportPlainXml(DwBuffer.Primary, 0, 0);
Console.WriteLine("ExportPlainXml: {0}", xml);
// Imports data from XML to DataStore
datastore.ImportRowFromXml(xml, 0, DwBuffer.Primary);
Console.WriteLine("After Import, Rowcount: {0}", datastore.RowCount);
/*This code produces the following output:
Before Import, Rowcount: 1
ExportPlainXml: <?xml version="1.0" encoding="utf-16"?>
<ArrayOfD_Department>
<D_Department>
<Departmentid>1</Departmentid>
<Name>Development</Name>
<Budget>100</Budget>
<Startdate>2020-04-01T11:17:27</Startdate>
<Administrator>1</Administrator>
</D_Department>
</ArrayOfD_Department>
After Import, Rowcount: 2
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x