Hi
does anyone know, how the querylayer itself is created? i need to do exactyl the same as described (change the source of an existing querylayer). so the solution for getting the information of the existing layer is allready provided. but how do i create the new querylayer from the new source?
best regards
george
Hello,
Here is some sample code that shows how to create a Query Layer:
IWorkspaceFactory2 workspaceFactory = new SqlWorkspaceFactoryClass();
string connectionString = "dbclient=oracle11g;" + "serverinstance=190.100.100.200/MYMAP;" + "USER=SDE;" + "PASSWORD=SDE";
ISqlWorkspace sqlWorkspace = workspaceFactory.OpenFromString(connectionString, 0) as ISqlWorkspace;
IQueryDescription queryDescription = sqlWorkspace.GetQueryDescription("SELECT * FROM SDE.MYTABLE");
ITable table = pSqlWorkspace.OpenQueryClass("TestQueryTable", queryDescription);
IFeatureClass featureClass = table as IFeatureClass;
featureLayer.FeatureClass = featureClass;
axMapControl1.Map.AddLayer(pFeatureLayer as ILayer);
This is based on code posted by a user on another forum (https://code.csdn.net/snippets/229166).
In case it saves anyone else time in the future if they try using that snippet . . . The SqlWorkspaceFactory class doc says . . .
The SDEWorkspaceFactory.Open method should be used to make connections to all databases and enterprise geodatabases.