阅读:2427回复:6
MO出现AddNew Failed和Update Failed?
我用Delphi+MO+SDE For SQL Server开发地理信息系统。有的图层在调用Recs.AddNew时就出现异常,有的图层在Recs.Update时出现异常,不知是何原因,请各位高手指点迷津!
|
|
1楼#
发布于:2003-10-16 19:37
给出小段编辑程序看看?
|
|
|
2楼#
发布于:2003-10-16 22:03
procedure AddPolygons(recs: IMoRecordset);
var fields:IMoFields; field:IMoField; i:integer; shp:IMoPolygon; List:TStringList; begin List:=TStringList.Create; try GetFields(recs,List); fields:=recs.Fields; for i:=0 to m_polys.Count-1 do begin If recs.Updatable Then begin recs.AddNew; //有的SDE图层在这一步出错// field:=fields.Item('Shape'); shp:=m_polys.Items as IMoPolygon; field.Value:=shp; AddDefaultValue(Fields,List); recs.Update;//有的SDE图层在这一步出错// end; end; finally List.Free; end; ReleasePolygons; end; procedure AddDefaultValue(Fields:IMoFields;List:TStrings); var i:integer; Field:IMoField; begin for i:=0 to List.Count-1 do begin Field:=fields.Item(WideString(List.Strings)); case Field.Type_ of moLong :begin Field.Value:=0; end; moDouble :begin Field.Value:=0; end; moDate :begin Field.Value:=Date; end; moString :begin Field.Value:='N'; end; moBoolean :begin Field.Value:=False; end; end; end; end; |
|
3楼#
发布于:2003-10-16 22:11
以上代码对于ShapeFile完全好使。
|
|
4楼#
发布于:2003-10-17 10:16
在esri的网上看过的一篇文章,和你的问题很类似,不过你的代码好象没有recs.StopEditing啊,看看下面的东东有没用:
Error Message When editing an ArcSDE layer in MapObjects, the following errors may occur: Run-time error 5017: Edit failed Run-time error 5019: Update failed Cause The Shape field value in the record may contain a NULL value. Return the value of the ExtendedErrorString property on the DataConnection object. If the value returned is 'Column is NULL', the Shape field contains a NULL. Solution or Workaround Convert each NULL shape value to NIL. You will need to do this in a C program. MapObjects does not support this functionality. A NULL shape has no FeatureID (FID) and no geometric data. There is an entry in the Business Table but no entry in the Feature Table. The Update method in MapObjects fails because it can't find the FeatureID. Another test is to compare the number of entries in the Business Table against the number of entries in the Feature Table. When these values differ, your layer contains NULL shapes. A NIL shape, on the other hand, has an entry in the Business Table and an entry in the Feature Table. Thus, a NIL shape has a FeatureID (FID). MapObjects uses this FeatureID to access the record and can successfully Update. |
|
|
5楼#
发布于:2003-10-17 11:03
对了,对于Update Failed的情况,如果从另一个图层(不论是ShapFile layer还是SDE Layer)导入图形(也就是说m_polys中存放的图形是从Layer.Records得到的),可以导入到SDE Layer中。而对于m_polys列表中存放的是用TrackPolygon方法绘制的图形,则无法导入到SDE Layer中。所以我想,是不是用TrackPolygon方法绘制的图形,信息不全面,SDE Layer无法接受呀?
对于,AddNew Failed,我认为是图层本身的属性导致不让增加记录。但我不知道怎么解决。 |
|
6楼#
发布于:2003-10-17 13:00
这里是个把trackinglayer对象保存到sde layer和shp layer中的例子:
http://www.gisempire.com/bbs/dispbbs.asp?boardID=39&ID=6861 |
|
|