I am trying to point all layers in MXD files to a different database server. Databse server is Oracle type. Most of the layers consist of views. After changing the datasource programatically for all layers, when I try to open attribute table for layer, attribute table is empty. But if I save MXD and open it in ArcMap, I can see data in attribute table. I tried below code but it didn't work.

                ITableWindow pTableWindow = new TableWindowClass();
                pTableWindow.Application = ArcMap.Application;
                ITableWindow3 pTableWindow3 = pTableWindow as ITableWindow3;
                ISet pTableSet = new SetClass();
                pTableWindow3.FindOpenTableWindows(out pTableSet);

                ITableWindow pTableWindowTemp = pTableSet.Next() as ITableWindow;

                while (pTableWindowTemp != null)
                    pTableWindowTemp = pTableSet.Next() as ITableWindow;
  • Have you tried IContentsView.Refresh? resources.arcgis.com/en/help/arcobjects-net/componenthelp/… do you have the tables open in your document? Are you running this from Catalog or Map? It's not clear from you snippet. – Michael Stimson Jun 11 '18 at 22:09
  • When you pointed to different datasets did you call IDataLayer2.Disconnect and then IDataLayer2.Connect after assiging a new DatasourceName? Doing this is sometimes helps notify things (like table windows) that they need to refresh. – Kirk Kuykendall Jun 11 '18 at 22:43
  • @MichaelStimson, /**Code Start***/ string queryClassName = ""; sw.CheckDatasetName(mapLayer.Name, qd, out queryClassName); IFeatureClass newFc = sw.OpenQueryClass(queryClassName, qd) as IFeatureClass; (mapLayer as IFeatureLayer).FeatureClass = newFc; mxDoc.UpdateContents(); mxDoc.ActiveView.Refresh(); /*** Code Ends***/ This is what i did in code to update layer – jay Jun 11 '18 at 23:15
  • Try mxDoc.ContentsView.Refresh() after updating, this will update the TOC and should fire the updates to your tables. It is always preferable to edit your code into your question, it's very hard to read all jumbled up in a comment. – Michael Stimson Jun 11 '18 at 23:56
  • @MichaelStimson, I guess your code is not valid in c#. Look at the link below. [link] edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriArcMapUI/… – jay Jun 12 '18 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.