DataStoreExtensions.ImportString(DataFormat importType, string text, int startRow = 0, int endRow = -1, int startColumn = 0, int endColumn = -1, int dwStartColumn = 0) Method
.NET Standard 2.x
Inserts the data from a string to DataStore. The string can be in the format of JSON, XML, or TXT.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public static int ImportString(this IDataStoreBase dataStore, DataFormat importType, string text, int startRow = 0, int endRow = -1, int startColumn = 0, int endColumn = -1, int dwStartColumn = 0);
Parameters
importType
SnapObjects.Data.DataFormat
The type of the data to be inserted. Currently the support types are DataFormat.Json, DataFormat.Xml, and DataFormat.Text.
text
System.String
A string which contains the data to be inserted.
startRow
System.Int32
The number of the first detail row in the string that you want to import. The default is 0
.
endRow
System.Int32
The number of the last detail row in the string that you want to import. The default is the rest of the rows.
startColumn
System.Int32
The number of the first column in the string that you want to import. The default is 0
.
endColumn
System.Int32
The number of the last column in the string that you want to import. The default is the rest of the columns.
dwStartColumn
System.Int32
The number of the first column in the DataStore that should receive data. The default is 0
.
bufferType
DwNet.Data.DwBuffer
Returns
System.Int32
Returns the number of rows that were imported if it succeeds.
Examples
The following code example imports data of the first and second columns in the first and second rows from a string into the DataStore primary buffer starting from the first column.
using System;
using DWNet.Data;
using SnapObjects.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DataStoreExtensionsExamples
{
public class ImportStringExample
{
private readonly SchoolContext _context;
public ImportStringExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates the datastore with datawindow: d_department.
var datastore = new DataStore("d_department");
// Gets the string to import.
string importString = GetImportString();
// Imports the string to datastore.
datastore.ImportString(DataFormat.Text, importString, 0, 1, 0, 1, 0);
// Shows the total number of rows in the DataStore.
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
// Verifies whether a string is properly imported into the DataStore.
for (int row = 0; row < datastore.RowCount; row++)
{
Console.WriteLine("DepartmentID: {0}; Name: {1}",
datastore.GetItem<int>(row, "departmentid"),
datastore.GetItem<string>(row, "name"));
}
/*This code produces the following output:
Rowcount: 2
DepartmentID: 1; Name: Engineering
DepartmentID: 2; Name: English
*/
}
private string GetImportString()
{
// The string to be imported
return "1\tEngineering\t350000.0000\t9/1/2007 12:00:00 AM\t2\r\n" +
"2\tEnglish\t120000.0000\t9/1/2007 12:00:00 AM\t6\r\n" +
"4\tEconomics\t200000.0000\t9/1/2007 12:00:00 AM\t4\r\n";
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x