ArcMap retains fields of removed Table.

735
1
Jump to solution
03-14-2013 09:37 AM
DuncanHornby
MVP Notable Contributor
All,

I have developed an AddIn for ArcMap 10.1 using VB .net 2010.

My tool writes data it creates to a dBase file which gets loaded into the TOC. During processing the tool can create up to 25 fields.

Sometimes a user will need to rebuild this table with its initial set of 3 fields (by selecting a button on toolbar).

When the user clicks on the create table button my code searches for the table in the TOC and removes it with the following code:

 pStandAloneTableCollection.RemoveStandaloneTable(pStandAloneTable) pMXDocument.UpdateContents()


The code then continues by deleting the existing dBase file and then recreates with the default set of 3 fields. This all works fine. The table is loaded back into the TOC with the following code:

pStandAloneTable = New StandaloneTableClass pStandAloneTable.Table = pTable pStandAloneTable.Name = Me.TextBox1.Text pStandAloneTableCollection.AddStandaloneTable(pStandAloneTable) pMXDocument.UpdateContents()


If I then go to the Table in ArcMap and open it I see all the previous fields (with zero values) and not an attribute table with just 3 fields. It's as if ArcMap has held onto the schema of the table it had removed, any ideas on how to force a refresh?

Duncan
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
All,

FYI I resolved the problem, it appears to be with the way I was deleting the dBase file. Originally I was deleting the table using the following code:

My.Computer.FileSystem.DeleteFile(sFullPath)


I changed this to the more verbose method using ArcObjects:

Dim pWorkspaceFactory As IWorkspaceFactory pWorkspaceFactory = New ShapefileWorkspaceFactoryClass Dim pFeatureWorkspace As IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sPath, 0) pTable = pFeatureWorkspace.OpenTable(Me.TextBox1.Text) Dim pDataset As IDataset pDataset = DirectCast(pTable, IDataset) If pDataset.CanDelete Then     ' Delete and clean up     pDataset.Delete()     pTable = Nothing     pTable = Nothing     pFeatureWorkspace = Nothing     pWorkspaceFactory = Nothing End If


This has resolved my problem.

View solution in original post

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
All,

FYI I resolved the problem, it appears to be with the way I was deleting the dBase file. Originally I was deleting the table using the following code:

My.Computer.FileSystem.DeleteFile(sFullPath)


I changed this to the more verbose method using ArcObjects:

Dim pWorkspaceFactory As IWorkspaceFactory pWorkspaceFactory = New ShapefileWorkspaceFactoryClass Dim pFeatureWorkspace As IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sPath, 0) pTable = pFeatureWorkspace.OpenTable(Me.TextBox1.Text) Dim pDataset As IDataset pDataset = DirectCast(pTable, IDataset) If pDataset.CanDelete Then     ' Delete and clean up     pDataset.Delete()     pTable = Nothing     pTable = Nothing     pFeatureWorkspace = Nothing     pWorkspaceFactory = Nothing End If


This has resolved my problem.
0 Kudos