コード例 #1
0
        public static List2D <object> ToList2D(this DataTable dataTable, bool includeColumnsName = true)
        {
            List2D <object> result = new List2D <object>(dataTable.Columns.Count);

            if (includeColumnsName)
            {
                for (int i = 0; i < dataTable.Columns.Count; ++i)
                {
                    result[i, 0] = dataTable.Columns[i];
                }
            }
            int offset = includeColumnsName ? 1 : 0;

            for (int i = 0; i < dataTable.Rows.Count; ++i)
            {
                if (offset == 0 && i != 0 || offset == 1)
                {
                    result.AddLine();
                }
                object[] row = dataTable.Rows[i].ItemArray;
                for (int j = 0; j < row.Length; ++j)
                {
                    result[j, i + offset] = row[j];
                }
            }
            return(result);
        }
コード例 #2
0
 public static List2D <object> ToList2D(this IDataReader dataReader, bool includeColumnsName = true)
 {
     using (dataReader)
     {
         List2D <object> result = new List2D <object>(dataReader.FieldCount);
         if (includeColumnsName)
         {
             for (int i = 0; i < dataReader.FieldCount; ++i)
             {
                 result[i, 0] = dataReader.GetName(i);
             }
         }
         int j = includeColumnsName ? 1 : 0;
         while (dataReader.Read())
         {
             if (j != 0)
             {
                 result.AddLine();
             }
             for (int i = 0; i < dataReader.FieldCount; ++i)
             {
                 result[i, j] = dataReader[i];
             }
             j++;
         }
         return(result);
     }
 }