Show / Hide Table of Contents

    DwDataTableExtensions.GetDataExporter(DataFormat dataFormat) Method

    .NET Standard 2.x

    Gets the DataTable exporter. You need to specify the data export DataFormat.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public static IDataExporter GetDataExporter(this DataTable dataTable, DataFormat dataFormat)
    

    Parameters

    dataFormat SnapObjects.Data.DataFromat

    The format of the exported data.

    Returns

    SnapObjects.Data.IDataExporter

    The DataTable data exporter.

    Examples

    The following code example demonstrates how to get data exporter in the specified format.

    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    using System.Data;
    
    namespace Appeon.ApiDoc.DwDataTableExtensionsExamples
    {
        public class GetDataExporterExample
        {
            private readonly SchoolContext _context;
    
            public GetDataExporterExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Initializes a DataTable.
                var table = new DataTable();
                table.Columns.Add("DepartmentID", typeof(int));
                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("Budget", typeof(decimal));
                table.Columns.Add("StartDate", typeof(DateTime));
                table.Columns.Add("Administrator", typeof(int));
    
                // Adds a row of data.
                var row = table.NewRow();
                row["DepartmentID"] = 1;
                row["Name"] = "Engineering";
                row["Budget"] = 10000;
                row["StartDate"] = DateTime.Now;
                row["Administrator"] = 2;
                table.Rows.Add(row);
    
                // Gets DataTable exporter in JSON format
                var exporter = table.GetDataExporter(DataFormat.Json);
    
                // Exports all data, including the column heading of the DataWindow.
                string export_json = exporter.Export();
                Console.WriteLine("Export Json: {0}", export_json);
    
                /* The exported JSON file is:
                
                ExportJson1.json
                */
    
                // Exports only the first column of the first row.
                export_json = exporter.Export(0, 0, 0, 0);
                Console.WriteLine("Export Json: {0}", export_json);
    
                /* The exported JSON file is: 
                
                ExportJson2.json
                */
    
                // Exports all data, excluding the column headers of the DataWindow.
                string exportPlain_json = exporter.ExportPlain();
                Console.WriteLine("ExportPlain Json: {0}", exportPlain_json);
    
                /* The exported JSON file is: 
    
                ExportPlainJson1.json
                */
    
                // Exports only the first column of the first row.
                exportPlain_json = exporter.ExportPlain(0, 0, 0, 0);
                Console.WriteLine("ExportPlain Json: {0}", exportPlain_json);
    
                /*This code produces the following output:
              
                ExportPlain Json: [{\"DepartmentID\":1}]
                */
            }
        }
    }
    

    Example Refer To

    JSON Files: ExportJson1 ExportJson2 ExportPlainJson1

    Back to top Generated by Appeon