DataStoreDataExtensions.ImportString(this IDataStoreBase dataStore, string text, int startRow, int endRow, int startColumn, int endColumn) Method
.NET Standard 2.x
Inserts the tab-separated data from a string into the DataStore. You can specify the starting and ending rows and columns in the string to import.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static int ImportString(this IDataStoreBase dataStore, string text, int startRow, int endRow, int startColumn, int endColumn);
Parameters
text
System.String
A string from which you want to copy the data. The string should contain tab-separated columns.
startrow
System.Int32
The zero-based number of the first row in the string that you want to import. If it is negative, 0
is used.
endRow
System.Int32
The zero-based number of the last row in the string that you want to import. If it is negative, the rest of the rows will be imported.
startColumn
System.Int32
The zero-based number of the first column in the string that you want to import. If it is negative, 0
is used.
endColumn
System.Int32
The zero-based number of the last column in the string that you want to copy. If it is negative, the rest of the columns will be imported.
Returns
System.Int32
Returns the number of rows that were imported if it succeeds.
Remarks
The string must be formatted in tab-separated. Each line must end with a carriage return and a newline character (~r~n). If the string has four tab-separated columns, one line might look like for a tab-separated string:
col1_data\t col2_data\t col3_data\t col4_data\r\n
The string should consist of rows of data. If the data includes column headings or row labels, set the startRow
and startColumn
arguments to skip them. The datatype and order of the DataStore columns must match with the columns of data in the string.
Examples
The following code example demonstrates how to import the department records from a string to a DataStore using the startRow
, endRow
, startColumn
and endColumn
parameters.
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ImportStringExample
{
private readonly SchoolContext _context;
public ImportStringExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example5()
{
// Instantiates the datastore with datawindow: d_department2
var datastore = new DataStore("d_department2", _context);
// Gets the string to be imported.
string importString = GetImportString();
// Imports data in the first and second rows of the string to the datastore
// Imports data in columns (2nd through 6th) of the string to the datastore
// datastore: d_department2 has no departmentid column
datastore.ImportString(importString, 0, 1, 1, 5);
Console.WriteLine("Rowcount: {0}", datastore.RowCount);
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine("Name: {0}; Budget: {1}",
datastore.GetItem<string>(row, "name"),
datastore.GetItem<decimal>(row, "budget"));
}
/*This code produces the following output:
Rowcount: 2
Name: Engineering; Budget: 350000.0000
Name: English; Budget: 120000.0000
*/
}
}
}
Example Refer To
Model Class: D_Department2
DataWindow File: d_department2
Applies to
.NET Standard
2.x