ArcEngine对Blob字段赋值的方法

今天在测试数据入库程序,发现对某个图层操作之后,调用StopOperation,会出现“尝试写入或读取受保护的内存”错误。

经过测试,最终发现是因为该图层包含有Blob字段,而代码没有专门对Blob字段进行处理。

解决办法:
1、需要判断字段类型,如果是Blob类型,调用下面辅助方法获取Blob值:

IMemoryBlobStreamVariant varBlobStream = objFieldValue as IMemoryBlobStreamVariant;
if (varBlobStream == null) return null;
object objValue;
varBlobStream.ExportToVariant(out objValue);
byte[] bytesArray = objValue as byte[];

2、然后调用下面方法赋值:

IMemoryBlobStream pMBS = new MemoryBlobStreamClass();
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)pMBS;
object objValue = bytesArray;
varBlobStream.ImportFromVariant(objValue);
pFeature.set_Value(posField, varBlobStream);

你可能感兴趣的:(ArcEngine)