This project is read-only.

Adding Attributes to a FeatureSet

Feb 9, 2012 at 6:52 PM


I'm trying to add attributes to a FeatureSet using a System.Data.DataTable.  The DataTable is displayed in a DataGrid control.  I can create the attributes but none of the row values get transferred (basically I end up with an attribute table full of empty records).  I've tried a variety of things; here's my last attempt:

      Dim AttrTable As DataTable = grdData.DataSource.Clone()
      Dim i As Long
      For i = 0 To tab.Rows.Count - 1
      NewFeatureSet.DataTable = AttrTable

Any suggestions would be appreciated!

Feb 9, 2012 at 7:11 PM

The problem is not with populating the attribute table, it happens while exporting to a shapefile.  This code:

fl = Map1.GetFeatureLayers()(0)

Creates a shapefile with an attribute table, but the attribute row values are all blank ("0" for numeric columns and "" for string columns).

Feb 9, 2012 at 7:25 PM

Well, I found a work-around.  The solution is to independently save the attribute table using an AttributeTable object:

         Dim AttrTable As AttributeTable = New AttributeTable
         AttrTable.Table = fl.DataSet.DataTable
         AttrTable.SaveAs(Path.GetFileNameWithoutExtension(sfd.FileName) + ".dbf", True)

The line in red above saves the *.dbf shapefile attributes file, replacing the one that is created via the "ExportSelection" method (which results in an empty attributes table) with a fully populated set of attributes.