Show / Hide Table of Contents

    IDataStore.ImportString(string value) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Inserts the tab-separated data from a string into the DataStore.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public int ImportString(string value);
    

    Parameters

    value System.String

    A string from which you want to copy the data. The string should contain tab-separated columns.

    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 PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class ImportStringExample
        {
            private SchoolContext _context;
    
            public ImportStringExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates the datastore with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                string importString = GetImportString1();
    
                // Imports the string to datastore.
                datastore.ImportString(importString);
    
                Console.WriteLine("Rowcount: {0}", datastore.RowCount);
    
                for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
                {
                    Console.WriteLine("DepartmentID: {0}; Name: {1}; Budget: {2}",
                                      datastore.GetItem<int>(row, "departmentid"),
                                      datastore.GetItem<string>(row, "name"),
                                      datastore.GetItem<decimal>(row, "budget"));
                }
    
                /*This code produces the following output:
    
                DepartmentID: 1; Name: Engineering; Budget: 350000.0000
                DepartmentID: 2; Name: English; Budget: 120000.0000
                DepartmentID: 4; Name: Economics; Budget: 200000.0000
               */
            }
    
            private string GetImportString1()
            {
                // The string to be imported
                return "1\tEngineering\t350000.0000\t9/1/2007 12:00:00 AM\t2\n" +
                       "2\tEnglish\t120000.0000\t9/1/2007 12:00:00 AM\t6\n" +
                       "4\tEconomics\t200000.0000\t9/1/2007 12:00:00 AM\t4";
    
                /*This code produces the following output:
                 
                "Departmentid"  "Name"  "Budget"        "Startdate"     "Administrator"
                1       "Engineering"   350000.0000     9 / 1 / 2007 12:00:00 AM    2
                2       "English"       120000.0000     9 / 1 / 2007 12:00:00 AM    6
                4       "Economics"     200000.0000     9 / 1 / 2007 12:00:00 AM    4
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon