How to create DataTable with Data types in ASP.NET?
First we need to add below namespace for creating DataTable
in C#.NET.
using System.Data;
Declare a DataTable as below
DataTable dtDynamic = new DataTable();
Below code is useful for creating
DataTable with Parameters.
void CreateDynamicTable()
{
DataColumn dc = new DataColumn();
dc = new DataColumn();
dc.ColumnName = "MatTransSlNo";
dc.DataType
= Type.GetType("System.String");
dtDynamic.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "Amount";
dc.DataType
= Type.GetType("System.Decimal");
dtDynamic.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "DeleteFlag";
dc.DataType
= Type.GetType("System.Int32");
dtDynamic.Columns.Add(dc);
}
No comments:
Post a Comment