DataTable add column extension

Unfortunately there is no method to call DataTable.Add with the column size. This extension method will fix that:

1
2
3
4
5
6
7
8
public static DataColumn Add(this DataColumnCollection columns, string columnName, Type type, int maxLength)
{
  DataColumn column = new DataColumn(columnName, type);
  column.MaxLength = maxLength;
  columns.Add(column);

  return column;
}

0 Comments