Show / Hide Table of Contents

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

    .NET Standard 2.x

    Gets the DataTable object created by the specified element.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

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

    Parameters

    key System.String

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

    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.

    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 Example(IDataUnpacker dataUnpacker)
            {
                // Gets the DataTable object according to the key value
                var table = dataUnpacker.GetDataTable("student");
    
                // 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
                */
            }
        }
    }
    

    Example Refer To

    Controller Class: GetDataTableExampleController

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon