Solved! Go to Solution.
Hi, I'm having trouble getting access to the tables in a SQL SDE database using c# .Net. Could anyone please post an example of a connection and then getting accessing a table. My main goal is to take a table from the database (which is a centerline shapefile I loaded) and change its projection.
And take a different table and make it a dataset using IDataset or the geodatabse equivalent.Thanks.
public ITable GetTable( string query, string keyFieldName ) { IWorkspaceFactory2 workspaceFactory2; IWorkspace workspace; ISqlWorkspace sqlWorkspace; ITable table; using ( ComReleaser comReleaser = new ComReleaser() ) { // create types Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.SqlWorkspaceFactory" ); workspaceFactory2 = Activator.CreateInstance( factoryType ) as IWorkspaceFactory2; workspace = workspaceFactory2.OpenFromString( this.connection, 0 ); sqlWorkspace = workspace as ISqlWorkspace; // manage releasable objects comReleaser.ManageLifetime( workspaceFactory2 ); comReleaser.ManageLifetime( sqlWorkspace ); // prepare query IQueryDescription queryDescription = sqlWorkspace.GetQueryDescription( query ); queryDescription.OIDFields = keyFieldName; // get a unique name string datasetName = "S"; sqlWorkspace.CheckDatasetName( "S", queryDescription, out datasetName ); // execute table = sqlWorkspace.OpenQueryClass( datasetName, queryDescription ); } return table; }
Hi, I'm having trouble getting access to the tables in a SQL SDE database using c# .Net. Could anyone please post an example of a connection and then getting accessing a table. My main goal is to take a table from the database (which is a centerline shapefile I loaded) and change its projection.
And take a different table and make it a dataset using IDataset or the geodatabse equivalent.Thanks.
public ITable GetTable( string query, string keyFieldName ) { IWorkspaceFactory2 workspaceFactory2; IWorkspace workspace; ISqlWorkspace sqlWorkspace; ITable table; using ( ComReleaser comReleaser = new ComReleaser() ) { // create types Type factoryType = Type.GetTypeFromProgID( "esriDataSourcesGDB.SqlWorkspaceFactory" ); workspaceFactory2 = Activator.CreateInstance( factoryType ) as IWorkspaceFactory2; workspace = workspaceFactory2.OpenFromString( this.connection, 0 ); sqlWorkspace = workspace as ISqlWorkspace; // manage releasable objects comReleaser.ManageLifetime( workspaceFactory2 ); comReleaser.ManageLifetime( sqlWorkspace ); // prepare query IQueryDescription queryDescription = sqlWorkspace.GetQueryDescription( query ); queryDescription.OIDFields = keyFieldName; // get a unique name string datasetName = "S"; sqlWorkspace.CheckDatasetName( "S", queryDescription, out datasetName ); // execute table = sqlWorkspace.OpenQueryClass( datasetName, queryDescription ); } return table; }