1、创建新表
/// <summary>
/// 创建一个只有ZID的数据表
/// </summary>
/// <param name="path">属性表文件路径(包括属性名)</param>
/// <returns></returns>
static public ITable CreateTable(string path)
{
string _TablePath = Path.GetDirectoryName(path);
string _TableName = Path.GetFileName(path);
IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;
//添加字段
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "ZID";//字段名称
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;//字段类型
//用于添加表中的必要字段
ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription =
new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();
IFields pTableFields = objectClassDescription.RequiredFields;
IFieldsEdit pFieldsEdit = pTableFields as IFieldsEdit;
pFieldsEdit.AddField(pField);
ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");
return pTable;
}
2、向已有表中添加字段
ITable pTable = CreateTable(path);
IField pFieldValue = new FieldClass();
IFieldEdit pFieldEdit = pFieldValue as IFieldEdit;
pFieldEdit.Name_2 = "面积比";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
pTable.AddField(pFieldValue);
3、设置属性值(增)
IRow pRow = pTable.CreateRow();
pRow.set_Value(1, value1);
pRow.set_Value(2, value2);
pRow.Store();