Cursor的理解
使用Cursor 新增数据
public static void InsertCursor(IMap map)
{
if (map != null && map.LayerCount > 0)
{
IFeatureLayer fclLayer = map.get_Layer(0) as IFeatureLayer;
IFeatureClass fcls = fclLayer.FeatureClass;
if (fcls != null)
{
ITable table = fcls as Table;
ICursor insertCursor = table.Insert(true);
IRowBuffer row = table.CreateRowBuffer();
int index = table.Fields.FindField("bz");
if (index > 0)
{
row.set_Value(index, "cs0");
insertCursor.InsertRow(row);
}
insertCursor.Flush();
}
}
}
使用Cursor 修改数据
public static void UpdateCursor(IMap map)
{
IFeatureLayer fclLayer = map.get_Layer(0) as IFeatureLayer;
IFeatureClass fcls = fclLayer.FeatureClass;
if (fcls != null)
{
ITable table = fcls as Table;
IQueryFilter filter = new QueryFilter();
filter.SubFields = "bz";
filter.WhereClause = string.Format("bz='{0}'", "cs");
ICursor updateCursor = table.Update(filter, true);
if (updateCursor != null)
{
IRow row = updateCursor.NextRow();
while(row!=null){
int indexBZ = row.Fields.FindField("bz");
if(indexBZ>0){
row.set_Value(indexBZ,"cs1");
}
updateCursor.UpdateRow(row);
row = updateCursor.NextRow();
}
updateCursor.Flush();
}
}
}