IDataPacker.GetDataTable([NotNull]this IDataPacker dataPacker,[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 IDataPacker dataPacker,
[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 IDataPacker
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.IDataPackerExamples
{
public class GetDataTableExample
{
private readonly SchoolContext _context;
public GetDataTableExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example2(IDataPacker dataPacker)
{
// Gets the DataTable object according to the key.
var table = dataPacker.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
*/
}
}
}
Applies to
.NET Standard
2.x