问题描述: 我在服务器中已经建立好mysql数据库,然后在数据库中已经按照相关的规范用超图的idesktop建立好了相应的空间表,然后我在我的项目里面连接数据库打开工作空间进行导入数据时发现我无法进行追加导入数据,比如我 数据库中已经建立好名为Test的空间表,然后我无法通过DataImport的方式导入进去,我只能命名一个数据库中不存在的数据集,才能导入进去,它会自动帮我创建一张新的表,然而这并不是我想要的,我只是想将我加载的shp数据导入到我指定的表中。
DatasourceConnectionInfo connectionInfo = null;
Workspace workspace = null;
connectionInfo = new DatasourceConnectionInfo();//保存数据源连接信息的组件
connectionInfo.Server = "192.168.10.80";//以下设置相关信息
connectionInfo.Database = "supermap";
connectionInfo.User = "root";
connectionInfo.Password = "123";
connectionInfo.EngineType = EngineType.MySQL;
connectionInfo.Driver = "MySQL";
try
{
workspace = new Workspace();//在一个工作空间中打开
workspace.Datasources.CloseAll();//先清空工作空间的数据源
Datasource datasources = workspace.Datasources.Open(connectionInfo);
//bool isOpen = test.Open(workSpace);
DataImport m_dataImport = new DataImport();
ImportSettingSHP shpSetting = new ImportSettingSHP();
shpSetting.ImportMode = ImportMode.Append;
shpSetting.SourceFilePath = @"D:\内网通缓存\本机数据\210922彰武县\矢量数据\LQ2109222018.shp";
shpSetting.TargetDatasource = datasources;
ImportDataInfos dataInfos = shpSetting.GetTargetDataInfos("");
ImportDataInfoSHP info = dataInfos[0] as ImportDataInfoSHP;
info.TargetName = "Test";
shpSetting.SetTargetDataInfos(dataInfos);
m_dataImport.ImportSettings.Add(shpSetting);
m_dataImport.Run();
DatasetVector importResult = datasources.Datasets["Test"] as DatasetVector;
}
catch (Exception ex)
{
workspace.Dispose();
}