AnsweredAssumed Answered

How to add ITable to ArcMap TOC

Question asked by Yiman on Jul 16, 2012
Latest reply on Jul 16, 2012 by Yiman
Is there anyway to add ITable to ArcMap TOC? I'm trying to edit a table which is added through WorkspaceFactory.OpenFromFile. But I get the error "Error HRESULT E_FAIL has been returned from a call to a COM component", see the code below. I found out that if I add a featurelayer along with the table and add the featurelayer to TOC, I don't get the error. Any suggestions?

            IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactory();             IWorkspace workspace = pWorkspaceFactory.OpenFromFile(path, 0);             IPropertySet propSet = workspace.ConnectionProperties;              IFeatureWorkspace pWorkspace = pWorkspaceFactory.Open(propSet, 0) as IFeatureWorkspace;             ITable table = pWorkspace.OpenTable("GISLCSA.GISEDITOR.MetaID");             ILayer tableLayer = table as ILayer;             pMetaIDTable = table as ITable;              UID uid = new UIDClass();             uid.Value = "esriEditor.Editor";             IEditor editor = m_application.FindExtensionByCLSID(uid) as IEditor;              if (editor.EditState == esriEditState.esriStateNotEditing)             {                 try                 {                     editor.StartEditing(workspace );                 }                 catch (Exception e)                 {                     MessageBox.Show(e.Message);                 }             }

Outcomes