Example #1
0
        private DataTable CreateDataTable(string tableName, DbfReader reader)
        {
            DataTable dataTable = new DataTable(tableName);

            DbfFieldDesc[] fieldDescriptions = reader.DbfRecordHeader.GetFieldDescriptions();

            //create the columns
            dataTable.Columns.Add(ShapeFileRecordIndexColumnName, typeof(Int32));
            dataTable.Columns.AddRange(DataColumnsFromDbfFields(fieldDescriptions));

            //add the data
            object[] rowValues = new object[fieldDescriptions.Length + 1];
            for (int n = 0; n < reader.DbfRecordHeader.RecordCount; ++n)
            {
                string[] values = reader.GetFields(n);
                TrimArrayValues(values);
                rowValues[0] = n;
                GetDataValues(fieldDescriptions, values, rowValues, 1);

                DataRow row = dataTable.NewRow();
                row.ItemArray = rowValues;
                dataTable.Rows.Add(row);
            }

            return(dataTable);
        }