文章目录
一、简述
使用IFeatureWorkspace.CreateFeatureClass在MDB中新建要素类时,运行报错(“Microsoft Jet 数据库引擎找不到输入表或查询 ‘GDB_DataChanges’。 确定它是否存在,以及它的名称的拼写是否正确。”)
报错代码段
// 以下代码运行时,会报错
ISpatialReference pSpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference;
IGeometryDefEdit pGeoDef = new GeometryDefClass();
IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
pGeoDefEdit.SpatialReference_2 = pSpatialReference;
IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
IField pField = new FieldClass();
IFieldEdit pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "SHAPE";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
pFieldsEdit.AddField(pField);
pFieldEdit.GeometryDef_2 = pGeoDef;
pField = new FieldClass();
pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "STCD";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldsEdit.AddField(pField);
pField = new FieldClass();
pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "SLM10";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldsEdit.AddField(pField);
IWorkspaceFactory pFtWsFct = new AccessWorkspaceFactoryClass();
IFeatureWorkspace pWs = pFtWsFct.OpenFromFile(@"D:\Test\arcmdx\444.mdb", 0) as IFeatureWorkspace;
IFeatureClass pFtClass = pWs.CreateFeatureClass("Test", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", null);
报错截图如下:
二、解决方法
1.修改空间参考,将第一行代码修改如下:
// 修改的部分
ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatialReference = spatialReferenceFactory.CreateSpatialReference((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
//ISpatialReference pSpatialReference = axMapControl1.ActiveView.FocusMap.SpatialReference;导致报错的代码