|
/// <summary>
/// DataTable扩展类
/// </summary>
public static class DataTableExtensions
{
/// <summary>
/// 显示DataTable的结构信息
/// </summary>
/// <param name="table">datatable</param>
public static void LoadDataTableStructure(this DataTable table)
{
if (table == null)
{
System.Diagnostics.Debug.WriteLine("datatable is null.");
}
StringBuilder structureInfo = new StringBuilder();
string colName = string.Empty;
string colType = string.Empty;
structureInfo.AppendLine("============================Begin=============================");
structureInfo.AppendLine("TableName: " + table.TableName);
structureInfo.AppendLine(string.Format("{0,-20}{1}", "ColumnName", "DataType"));
foreach (DataColumn col in table.Columns)
{
colName = col.ColumnName;
colType = col.DataType.ToString();
structureInfo.AppendLine(string.Format("{0,-20}{1}", colName, colType));
}
structureInfo.AppendLine("=============================End==============================");
System.Diagnostics.Debug.WriteLine(structureInfo.ToString());
}
}
|
|