DataStoreDataExtensions.ImportXmlByKey(this IDataStoreBase dataStore, string text, DwBuffer dwuffer, int startRow) Method
.NET Standard 2.x
Inserts data from an XML string into the specified buffer of DataStore according to the key name of the XML item. You can specify the starting position in the XML array.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int ImportXmlByKey(this IDataStoreBase dataStore, string text, DwBuffer dwbuffer, int startRow);
Parameters
text
System.String
A string specifying the XML data.
The XML string must comply with the plain-format XML or DataWindow XML.
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 XML: Imports the XML data to the specified buffer.
For DataWindow XML: Imports data from the specified buffer from the XML string to the corresponding buffer.
startRow
System.Int32
The zero-based number of the first row in the XML array that you want to import. If it is negative, 0
is used.
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 first row in an XML string to the specified buffer.
using DWNet.Data;
using System;
using System.IO;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ImportXmlByKeyExample
{
private readonly SchoolContext _context;
public ImportXmlByKeyExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example3()
{
// Instantiates the datastore with datawindow: d_department
var datastore = new DataStore("d_department", _context);
// Gets the XML file. ExportPlainXml1.xml contains 2 records.
string path = Path.Combine(AppContext.BaseDirectory,
@"Xmls\IDatastore\ExportPlainXml1.xml");
string xml = File.ReadAllText(path);
// Imports data from XML to the DataStore primary buffer.
// Starting from the first row.
datastore.ImportXmlByKey(xml, DwBuffer.Primary, 0);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
datastore.Reset();
// Imports data from the second row of the XML string to the primary buffer.
datastore.ImportXmlByKey(xml, DwBuffer.Primary, 1);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
/*This code produces the following output:
Rowcount: 2
Rowcount: 1
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x