-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTableUtils.cs
More file actions
39 lines (33 loc) · 919 Bytes
/
DataTableUtils.cs
File metadata and controls
39 lines (33 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Data;
using System.Reflection;
using System.Linq;
using System.Diagnostics;
namespace DataTableMakeSample
{
class DataTableUtils
{
public static DataTable GetDataTable(Type type)
{
DataTable table = new DataTable(type.Name);
foreach (Enum e in Enum.GetValues(type))
{
DataColumn column;
column = new DataColumn();
column.DataType = e.GetPropertyType();
column.ColumnName = e.GetProperty();
column.Caption = e.GetProperty();
Boolean isIdentification = (e.GetProperty() == "Id" ? true : false);
column.AutoIncrement = isIdentification;
column.ReadOnly = isIdentification;
column.Unique = isIdentification;
table.Columns.Add(column);
}
return table;
}
public static String GetName(Type type, Enum name)
{
return Enum.GetName(type, name);
}
}
}