ArcEngine对Blob字段赋值的方法

时间:2023-11-25 22:30:32

今天在测试数据入库程序,发现对某个图层操作之后,调用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);

来自:http://www.cnblogs.com/ITGIS/archive/2013/01/12/2857758.html