Show / Hide Table of Contents

    IDataUnpacker.GetDataTable([NotNull]this IDataUnpacker dataUnPackage, [NotNull]string key, [NotNull]MappingMethod importMapping) Method

    .NET Standard 2.x

    Gets the DataTable object created by the specified element. You can also specify the mapping method for importing data into the DataTable object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static DataTable GetDataTable(
    [NotNull]this IDataUnpacker dataUnPackage,
    [NotNull]string key,
    [NotNull]MappingMethod importMapping)
    

    Parameters

    key System.String

    The key specifying which element will be used to create the DataTable object.

    importMapping SnapObjects.Data.MappingMethod

    A value of the MappingMethod enumerated datatype specifying the method for mapping columns.

    Returns

    System.Data.DataTable

    Returns the newly created DataTable object.

    Examples

    The following code example gets the DataTable object in IDataUnPacker object according to the key and specifies the mapping method for importing data to the DataTable object.

    using SnapObjects.Data;
    using System;
    using System.Data;
    
    namespace Appeon.ApiDoc.IDataUnpackerExamples
    {
        public class GetDataTableExample
        {
            private readonly SchoolContext _context;
    
            public GetDataTableExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example2(IDataUnpacker dataUnpacker)
            {
                // Gets the DataTable object according to the key.
                var table = dataUnpacker.GetDataTable("student", MappingMethod.Key);
    
                // Shows the students.
                foreach (DataRow row in table.Rows)
                {
                    Console.WriteLine("First Name: {0}",
                        row["FirstName"]);
                    Console.WriteLine("Last Name: {0}",
                        row["LastName"]);
    
                    Console.WriteLine();
                }
    
                /* This code example produces the following output:
                
                First Name: Lena
                Last Name: Sherwood
    
                First Name: Davies
                Last Name: Adam
                */
    
                /* This code example produces the following output:
                
                The table name is: Grade
                */
            }
        }
    }
    

    Example Refer To

    Controller Class: GetDataTableExampleController

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon