GlobalId与普通的字段转换


// Converts a GlobalID field to a GUID field.
public static void ConvertGlobalIdToGuid(IWorkspace workspace, String
  datasetName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GlobalID field.
  IClassEx classEx = (IClassEx)table;
  if (!classEx.HasGlobalID)
  {
    throw new Exception(String.Format("No GlobalID column in table: {0}.",
      datasetName));
  }
  String globalIDFieldName = classEx.GlobalIDFieldName;

  // Convert the GlobalID column to a GUID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.UnregisterGlobalIDColumn(globalIDFieldName);
}

2 一下代码实现将普通的字段转变成GlobalID

/ Converts a GUID field to a GlobalID field.
public static void ConvertGuidToGlobalId(IWorkspace workspace, String
  datasetName, String guidFieldName)
{
  // Open the table.
  IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
  ITable table = featureWorkspace.OpenTable(datasetName);

  // Get the GUID field to convert.
  IFields fields = table.Fields;
  int guidFieldIndex = fields.FindField(guidFieldName);
  IField guidField = fields.get_Field(guidFieldIndex);
  if (guidField.Type != esriFieldType.esriFieldTypeGUID)
  {
    throw new Exception(String.Format("Field {0} is not a GUID field.",
      guidFieldName));
  }

  // Convert the GUID column to a GlobalID column.
  IClassSchemaEditEx classSchemaEditEx = (IClassSchemaEditEx)table;
  classSchemaEditEx.RegisterGlobalIDColumn(guidField.Name);
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值