使用ShapeLib读写dbf数据

来源:互联网 发布:淘宝店怎么卖充值卡 编辑:程序博客网 时间:2024/06/05 18:34

在批量更新dbf数据值时,使用ShapeLib读写dbf数据的效率非常惊人。

首先通过cvs获取ShapeLib库,http://shapelib.maptools.org/,编译生成shapelib.dll

下面重点讲一下怎么使用ShapeLib对dbf数据进行读写:

1、打开dbf

IntPtr hDbf = ShapeLib.DBFOpen(textBox1.Text, "rb+");//"rb"(只读)"rb+"(读/写)if (hDbf.Equals(IntPtr.Zero)){MessageBox.Show("打开dbf文件失败", "系统提示");}

2、获取字段索引

 int index = ShapeLib.DBFGetFieldIndex(hDbf, "名称");
3、读取字段值

StringBuilder str = new StringBuilder();ShapeLib.DBFReadStringAttribute2(hDbf, i,index, str);//读取字段的值,并将其作为字符串返回。
4、写入字段新值

ShapeLib.DBFWriteStringAttribute(hDbf, i, index, "字段新值");


通过以上4个步骤,就能实现dbf数据的读写了。

附上ShapeLib的帮助类:http://pan.baidu.com/s/1qWGE6hI

0 0