datatable增加自增列
/// <summary>
/// datatable增加自增列
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static DataTable AddAutoIdColumn(DataTable dt)
{
if (dt != null)
{
DataColumn autoColumn = new DataColumn("AutoID", System.Type.GetType("System.Int32"));
dt.Columns.Add(autoColumn);
dt.Columns["AutoID"].SetOrdinal(0);
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i][0] = i+1;
}
}
return dt;
}