Tuesday, September 22, 2009

Add Row Number to DataTable

public static DataTable AddRowNumber(DataTable dataTable)
{
dataTable.Columns.Add("RowNumber", typeof(int));
for (int i = 0; i < dataTable.Rows.Count; i++)
{
dataTable.Rows[i]["RowNumber"] = i;
}
dataTable.AcceptChanges();
return dataTable;
}

No comments: