I have membership database which contains Roles defined in the role table..Now i want to make datatable to be created dynamically from the the number of roles present in roles table...
here is my code..
DataTable dTable = new DataTable();
string[] rolesarr = Roles.GetAllRoles();
int length = rolesarr.Count();
for (int i = 0; i <= length; i++)
{
string colname = rolesarr[i];
if (i == 0)
{
dTable.Columns.Add(colname, typeof(string));
}
else
{
dTable.Columns.Add(colname, typeof(bool));
}
}
but it is giving error as
"System.IndexOutOfRangeException: Index was outside the bounds of the array."
Any help will be highly appreciated. Thanks in advance..