C#:数据库属性表的获取以及基本的增删改功能的实现
using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geodatabase; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace taihu2 { public partial class Form2 : Form { public Form2(ILayer pLayer) { InitializeComponent();//初始化图层; GetValues(pLayer);//获取图层数据; } //获取属性表方法 public void GetValues(ILayer pLayer) { dataGridView1.Rows.Clear();//清空dataGridview1的行; IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFields pFields = pFeatureLayer.FeatureClass.Fields; dataGridView1.ColumnCount = pFields.FieldCount;//把获得的字段的数量赋值给dataGridView的列数; for (int i = 0; i < pFields.FieldCount; i++) { string fieldname; fieldname = pFields.get_Field(i).Name; dataGridView1.Columns[i].Name = fieldname; } IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { string[] fldvalue = new string[pFields.FieldCount]; for (int i = 0; i < pFields.FieldCount; i++) { if (pFields.get_Field(i).Name == "Shape") { fldvalue[i] = Convert.ToString(pFeature.Shape.GeometryType); } else { fldvalue[i] = Convert.ToString(pFeature.get_Value(i)); } } dataGridView1.Rows.Add(fldvalue); pFeature = pFeatureCursor.NextFeature(); } } } }