您好!您要判断两个数据集的字段值是否一致,如果不一致,在后面追加该字段值的属性信息。部分代码如下:
// 获取两个数据集
DatasetVector dataset_world = workspace.Datasources[0].Datasets["World"] as DatasetVector;
DatasetVector dataset = workspace.Datasources[0].Datasets["Ocean"] as DatasetVector;
// 得到“Example”对应的所有记录集以及“World”中 SmID=1 的记录
Recordset recordset = dataset.GetRecordset(false, CursorType.Dynamic);
Recordset recordset_world = dataset_world.Query("SmID=2", CursorType.Static);
// 将记录位置移到第一位
recordset.MoveFirst();
string strfieldType;
if (recordset.FieldCount < recordset_world.FieldCount)
{
for (int i = 0; i < recordset_world.FieldCount; i++)
{
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.Name = recordset_world.GetFieldInfos()[i].Name;
fieldInfo.DefaultValue = recordset_world.GetValues()[i].ToString();
strfieldType = fieldInfo.Type.ToString ();
switch (strfieldType)
{
case "整型":
fieldInfo.Type = FieldType.Int32;
break;
case "双精度":
fieldInfo.Type = FieldType.Double;
break;
case "单精度":
fieldInfo.Type = FieldType.Single;
break;
case "字符型":
fieldInfo.Type = FieldType.Char;
break;
case "文本型":
fieldInfo.Type = FieldType.Text;
break;
}
if (i < recordset.FieldCount)
{
if (fieldInfo.Name != dataset.FieldInfos[i].Name)
{
dataset.FieldInfos.Add(fieldInfo);
}
}
else
{
dataset.FieldInfos.Add(fieldInfo);
}
}
}
recordset.MoveFirst();
// 将“World”中 SmID=1 的记录添加到 recordset 中并提交
Geometry geometry = recordset_world.GetGeometry();
recordset.AddNew(geometry);
recordset.Update();
// 关闭记录集,释放几何对象、记录集
recordset.Close();
geometry.Dispose();
recordset.Dispose();
recordset_world.Dispose();