直接上代码:
/// <summary> /// 修改空间数据库列值 /// </summary> private void EditSdeField() { //找到你的图层名 IFeatureClass featureCls = GetFeatureClass("平衡单元"); //得到该图层下有多少数据 int featureCount = featureCls.FeatureCount(null); //查询指定列名在表中的索引 int fieldIndex = featureCls.FindField("MAPDOCID"); IDataset ds = featureCls as IDataset; IWorkspace workspace = ds.Workspace; IWorkspaceEdit edit = workspace as IWorkspaceEdit; edit.StartEditing(false); edit.DisableUndoRedo(); IFeatureCursor updateCursor = featureCls.Update(null, false); edit.StartEditOperation(); IFeature feature = updateCursor.NextFeature(); while (feature != null) { feature.set_Value(fieldIndex, Guid.NewGuid().ToString("B")); updateCursor.UpdateFeature(feature); feature = updateCursor.NextFeature(); } edit.StopEditOperation(); edit.StopEditing(true); } public IFeatureClass GetFeatureClass(string layerName) { try { IFeatureWorkspace pFeatureWorkspace = DCIEngine.FrameWork.Global.m_pSDEWorkspace as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(layerName); return pFeatureClass; } catch (Exception) { return null; } }
要注意一点的就是arcgis的guid为{00000000-0000-0000-0000-000000000000} 形式,所以.net的guid 需要 ToString(“B”)转换为 他的格式。