您的位置:首页 > 数据库

C#粘贴复制数据库中的内容

2010-12-17 22:28 127 查看
// Create new workspace name objects. IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass();
IWorkspaceName targetWorkspaceName = new WorkspaceNameClass();
IName targetName = (IName)targetWorkspaceName;

// Set the workspace name properties.
sourceWorkspaceName.PathName = @
"C:\arcgis\ArcTutor\BuildingaGeodatabase\Montgomery.gdb";
sourceWorkspaceName.WorkspaceFactoryProgID =
"esriDataSourcesGDB.FileGDBWorkspaceFactory";
targetWorkspaceName.PathName = @"PartialMontgomery.gdb";
targetWorkspaceName.WorkspaceFactoryProgID =
"esriDataSourcesGDB.FileGDBWorkspaceFactory";

// Create a name object for the source feature class.
IFeatureClassName featureClassName = new FeatureClassNameClass();

// Set the featureClassName properties.
IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
sourceDatasetName.WorkspaceName = sourceWorkspaceName;
sourceDatasetName.Name = "Blocks";
IName sourceName = (IName)sourceDatasetName;

// Create an enumerator for source datasets.
IEnumName sourceEnumName = new NamesEnumeratorClass();
IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;

// Add the name object for the source class to the enumerator.
sourceEnumNameEdit.Add(sourceName);

// Create a GeoDBDataTransfer object and a null name mapping enumerator.
IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
IEnumNameMapping enumNameMapping = null;

// Use the data transfer object to create a name mapping enumerator.
Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName,
targetName, out enumNameMapping);
enumNameMapping.Reset();

// Check for conflicts.
if (conflictsFound)
{
// Iterate through each name mapping.
INameMapping nameMapping = null;
while ((nameMapping = enumNameMapping.Next()) != null)
{
// Resolve the mapping's conflict (if there is one).
if (nameMapping.NameConflicts)
{
nameMapping.TargetName = nameMapping.GetSuggestedName(targetName);
}

// See if the mapping's children have conflicts.
IEnumNameMapping childEnumNameMapping = nameMapping.Children;
if (childEnumNameMapping != null)
{
childEnumNameMapping.Reset();

// Iterate through each child mapping.
INameMapping childNameMapping = null;
while ((childNameMapping = childEnumNameMapping.Next()) != null)
{
if (childNameMapping.NameConflicts)
{
childNameMapping.TargetName = childNameMapping.GetSuggestedName
(targetName);
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: