Adding Attributes to a FeatureSet

Feb 9, 2012 at 5:52 PM

Hi,

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
         AttrTable.ImportRow(tab.Rows(i))
      Next
      NewFeatureSet.DataTable = AttrTable
      NewFeatureSet.FillAttributes()

Any suggestions would be appreciated!

Feb 9, 2012 at 6:11 PM

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

fl = Map1.GetFeatureLayers()(0)
fl.SelectAll()
fl.ExportSelection(FileName)
fl.UnSelectAll()

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 6:25 PM

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

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

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.

-norm