Hi,
When I try to add a table from a MDB to a MapControl's StandAloneTableCollection, I get an error. What am I doing wrong? The table exists and is not empty.
{System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.IStandaloneTable'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{FFC6B179-E3EC-11D3-A096-00C04F6BC626}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at <snip>.AddTableToMapControl() in <snip><snip>}
public void AddTableToMapControl()
{
IMapControl3 pMapControl = (IMapControl3)this.AxMapControl1.Object;
IWorkspaceFactory accessWorkspaceFactory = new AccessWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace;
ITable geodatabaseTable;
IStandaloneTable geodatabaseStTable;
IStandaloneTableCollection pStTableCollection = pMapControl as IStandaloneTableCollection;
try
{
featureWorkspace = accessWorkspaceFactory.OpenFromFile("c:/somewhere/somedb.mdb", 0) as IFeatureWorkspace;
geodatabaseTable = featureWorkspace.OpenTable("SomeTable");
geodatabaseStTable = (IStandaloneTable)geodatabaseTable; <----- here it fails with the error
pStTableCollection.AddStandaloneTable(geodatabaseStTable);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Many thanks,