internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
{
DataColumn sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];
if (null == sortindex)
{
sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(int));
dataTable.Columns.Add(sortindex);
}
int count = dataTable.Rows.Count;
for (int i = 0; i < count; ++i)
{
dataTable.Rows[i][sortindex] = i;
};
DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);
const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates);
Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows");
DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length];
for (int i = 0; i < dataRows.Length; ++i)
{
schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]);
}
return schemaRows;
}