still confused please help. Connect to SDE and get access to table

303
1
Jump to solution
03-16-2012 07:50 AM
jamesborris
New Contributor III
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.
Reply
0 Kudos
1 Solution

Accepted Solutions
GeorgeFaraj
Occasional Contributor III
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.


Get a table:

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; }

View solution in original post

Reply
0 Kudos
1 Reply
GeorgeFaraj
Occasional Contributor III
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.


Get a table:

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; }

View solution in original post

Reply
0 Kudos