C#Arcengine新建table表,并插入一行数据
时间: 2024-03-13 15:45:11 浏览: 57
arcengine,添加数据
5星 · 资源好评率100%
在C# ArcEngine中,可以使用以下代码来新建表和插入一行数据。假设我们要新建一个名为"myTable"的表,有一个名为"id"的整型主键和一个名为"name"的文本类型字段:
```csharp
//获取工作空间
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile("C:\data.gdb", 0);
//获取FeatureWorkspace
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
//创建表结构
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
fieldsEdit.AddField(CreateField("id", esriFieldType.esriFieldTypeInteger));
fieldsEdit.AddField(CreateField("name", esriFieldType.esriFieldTypeString));
//创建表
ITable table = featureWorkspace.CreateTable("myTable", fields, null, null, "");
//创建新行
IRow row = table.CreateRow();
row.set_Value(table.FindField("id"), 1);
row.set_Value(table.FindField("name"), "test");
//提交更改
row.Store();
```
其中,CreateField是一个自定义的方法,用于创建字段:
```csharp
private static IField CreateField(string name, esriFieldType type)
{
IField field = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)field;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
return field;
}
```
阅读全文