AnsweredAssumed Answered

Problem connecting with FileGeoDB table

Question asked by evtguy on Apr 26, 2012
Latest reply on Apr 26, 2012 by evtguy
I have a small subroutine in a VB.NET add-in I'm developing and it's sole purpose is to open a standalone table stored in a file geodatabase and add a new record to it. I searched through help and the forum to cobble together some similar code which compiles but errors once it's called. Here's the subroutine:

Public Sub addPhotoToGeoDatabase(ByVal theGTagInfo As geoTaggedInfo)         Try             Dim ptable As ITable              ' Create a file geodatabase workspace factory.             Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")             Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)              ' Create a file geodatabase.             Dim workspaceName As IWorkspaceName = workspaceFactory.OpenFromFile("G:\PublicWk\geoTagging\pwPhotoDatabaseTest.gdb", 0)              ' Open the geodatabase using the name object.             Dim Name As ESRI.ArcGIS.esriSystem.IName = CType(workspaceName, ESRI.ArcGIS.esriSystem.IName)             Dim workspace As IWorkspace = CType(Name.Open(), IWorkspace)              ' Cast the workspace to the IWorkspaceEdit2 interface.             Dim workspaceEdit As IWorkspaceEdit = CType(workspace, IWorkspaceEdit)              ' Start an edit session. An undo/redo stack isn't necessary in this case.             workspaceEdit.StartEditing(False)              ' Start an edit operation.             workspaceEdit.StartEditOperation()             ptable = workspace.OpenTable("tblGeotaggedPhotos")              ' Create a row. The row's attribute values should be set here and if             ' a feature is being created, the shape should be set as well.             Dim row As IRow = ptable.CreateRow()             row.Value("Latitude") = theGTagInfo.latitude             row.Value("Longitude") = theGTagInfo.longitude             row.Value("Descrip") = theGTagInfo.description             row.Value("Keywords") = theGTagInfo.keywords             row.Value("gTagByUser") = theGTagInfo.taggedByUserName             row.Value("gTagByFullName") = theGTagInfo.tageedByFullName             row.Value("DateGeotagged") = theGTagInfo.dateTagged             row.Value("FileName") = theGTagInfo.filename             row.Value("FullPath") = theGTagInfo.fullpath             row.Store()              ' Save the edit operation. To cancel an edit operation, the AbortEditOperation             ' method can be used.             workspaceEdit.StopEditOperation()              ' Stop the edit session. The saveEdits parameter indicates the edit session             ' will be committed.             workspaceEdit.StopEditing(True)              ptable = Nothing             row = Nothing             workspace = Nothing             workspaceEdit = Nothing             factoryType = Nothing             workspaceFactory = Nothing         Catch ex As Exception             globalErrorHandler(ex)         End Try     End Sub

and I have the following imported at the top of my module:

Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.Carto

When the subroutine is called, it gets to the following line and crashes:

Dim workspaceName As IWorkspaceName = workspaceFactory.OpenFromFile("G:\PublicWk\geoTagging\pwPhotoDatabaseTest.gdb", 0)

The exact error returned is..

ERROR DESCRIPTION:  Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.IWorkspaceName'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FADD975C-E36F-11D1-AA81-00C04FA33A15}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
TYPE OF ERROR:   System.InvalidCastException
STACK TRACE:   at geoTagPhotos2.usrFunctions.addPhotoToGeoDatabase(geoTaggedInfo theGTagInfo) in C:\Visual Studio 2008\Projects\geoTagPhotos2\geoTagPhotos2\usrFunctions.vb:line 407

So what am I doing wrong?

I was using a code snippit for creating a file geodatabase and I noticed that in that example, there's an ampersand (@) before the file path. Didn't know what that was about and if I needed it while using the OpenFromFile method.