Show / Hide Table of Contents

    IDataPacker.AddDataTable([NotNull]this IDataPacker packer,[NotNull]string key, [NotNull]DataTable value, bool changedOnly) Method

    .NET Standard 2.x

    Add a DataTable object as an element to the IDataPacker object, and specifies whether to export only the changed data from the DataTable object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static void AddDataTable(
    [NotNull]this IDataPacker packer,
    [NotNull]string key,
    [NotNull]DataTable value,
    [NotNull]bool changedOnly)
    

    Parameters

    key System.String

    The key for the element, which is the identifier of the element in the IDataPacker object.

    value System.Data.DataTable

    The DataTable object, which is the value of the element to be added to the IDataPacker object.

    changedOnly System.Boolean

    System.Boolean

    True -- to export the changed rows in the DataTable object only (the row state is in DataRowState.Added, DataRowState.Deleted or DataRowState.Modified).

    False -- to export all rows in the DataTable object.

    Examples

    The following code example adds a DataTable object as an element to the IDataPacker object and uses the DataTable name as the key name for the element. And it adds the changed rows only.

    using SnapObjects.Data;
    using System;
    using System.Data;
    
    namespace Appeon.ApiDoc.IDataPackerExamples
    {
        public class AddDataTableExample
        {
            private readonly SchoolContext _context;
    
            public AddDataTableExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example2()
            {
                var packer = new DataPacker();
    
                // Creates a DataTable object
                var dataTable = new DataTable("Grade");
    
                // Creates columns
                DataColumn dc = new DataColumn("NO", typeof(String));
                dataTable.Columns.Add(dc);
    
                // Inserts data
                DataRow dr = dataTable.NewRow();
                dr[0] = "1000";
                dataTable.Rows.Add(dr);
    
                // Adds dataTable object to the current IDataPacker and exports only the changed data
                var key = nameof(dataTable);
                packer.AddDataTable(key, dataTable, true);
    
                // Gets and shows all of the data values in JSON format
                Console.WriteLine(packer.GetTextString(DataFormat.Json));
    
                /* This code example produces the following output:
                
                {"dataTable":[{"NO":"1000"}]}
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon