/// <summary>
/// This method creates and returns a DataTable with given field
/// </summary>
///<param name="lstFields"></param>
///<returns>DataTable</returns>
public static DataTable CreateDataTable(object[] lstFields)
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
foreach (object obj in lstFields)
{
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = obj.ToString();
if (obj.ToString() == "pk")
{
myDataColumn.AutoIncrementSeed = 1;
myDataColumn.AutoIncrement = true;
}
else
myDataColumn.DefaultValue = obj.ToString();
myDataTable.Columns.Add(myDataColumn);
}
return myDataTable;
}
/// This method creates and returns a DataTable with given field
/// </summary>
///<param name="lstFields"></param>
///<returns>DataTable</returns>
public static DataTable CreateDataTable(object[] lstFields)
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
foreach (object obj in lstFields)
{
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = obj.ToString();
if (obj.ToString() == "pk")
{
myDataColumn.AutoIncrementSeed = 1;
myDataColumn.AutoIncrement = true;
}
else
myDataColumn.DefaultValue = obj.ToString();
myDataTable.Columns.Add(myDataColumn);
}
return myDataTable;
}
No comments:
Post a Comment