//udb文件,数据集添加新字段没成功,导致新字段内容赋值失败
Workspace m_workspace = new Workspace();
Datasources m_datasources = m_workspace.Datasources;
Scene scene = new Scene();
DatasourceConnectionInfo datasourceConnectionInfo = new DatasourceConnectionInfo(@"TianYuanLu.udb", "recordset", "");
Datasource m_datasource = m_datasources.Open(datasourceConnectionInfo);
DatasetVector dataset = m_datasource.Datasets["NewDataset_01"] as DatasetVector;
string newFileldName = "新字段_yf";
Recordset recordset = dataset.GetRecordset(false, CursorType.Dynamic);
Object[] o = recordset.GetValues();
FieldInfos fieldInfos = recordset.GetFieldInfos();
//添加新字段
if (fieldInfos.IndexOf(newFileldName) != -1)
{
Console.WriteLine(newFileldName);
return;
}
FieldInfo layerField = new FieldInfo(newFileldName, FieldType.Text);
layerField.IsRequired = false;
layerField.DefaultValue = "新图层";
layerField.Caption = newFileldName;
fieldInfos.Add(layerField);
//刷新记录集
recordset.Update();
Object[] o2 = recordset.GetValues();
bool isSuc1 = recordset.SetFieldValue("图层名称", "测试修改图层名称");
//对新字段赋值
bool isSuc2 = recordset.SetFieldValue(newFileldName, "图层名称_YF");
//刷新记录集
recordset.Update();