I'm using C# to get the actual datasourcename of each layer in the Table of Contents of an MXD (example: sde.SomeDatabase.Cities is the datasourcename for the Cities Table). My code is blowing up when I try to capture this datasourcename so is my code not right or are there better ways to capture this name for a Table?
IStandaloneTable pStTable;
ITable pFromTable;
ILayer pTableLayer;
IDataLayer pDatalyr;
pTabCollection = pMap as IStandaloneTableCollection;
for (int u = 0; u < pTabCollection.StandaloneTableCount; u++)
{
pFromTable = pTabCollection.StandaloneTable as ITable;
pDatalyr = pFromTable as IDataLayer;
string test = pDataLayer.DataSourceName.ToString().ToUpper(); //Code blowing up here
//.......... additional code
}