来自:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=28859&extra=page%3D1%26amp%3Bfilter%3Dtype%26amp%3Btypeid%3D6
利用IFDOToADOConnection 对属性表浏览 速度很快哦!
题外话:呵呵,最近在做个项目,对于使用的每个Shp文件都要浏览其属性表,可我使用的每个文件里的Feature都达到了五位数以上,用一般的方法浏览其属性表实在是太长时间了,于是乎想到了这个接口,在9.2中对这个接口和ADO的连接进行了比较详细的说明,但是没有说明怎么和像DataGridView和DataGrid这样的控件进行绑定的问题,对于初学者是个比较头疼的问题,这里我给大家两个个例子仅供参考,呵呵。 一、浏览属性的一般方法(要是文件里的Feature数目不多,这个方法还是可行的,控件采用的是ListView) try { if (layer != null) { ILayer ipLyr = GetLayerByName(layer.Name); IFeatureLayer ipFLayer = ipLyr as IFeatureLayer; ITable ipTable = ipFLayer as ITable; int count = ipTable.RowCount(null); if (count == 0) { MessageBoxEx.Show("该图层无实体数据可查询"); return; } frmShowFeatures frmShowF = new frmShowFeatures(ipLyr, mapControl); frmShowF.lblFeaCount.Text = "该图层共有" + count.ToString() + "个要素"; string strGeoType = ReturnGeoType(ipTable.GetRow(0).Fields.get_Field(1)); for (int j = 0; j < ipTable.Fields.FieldCount; j++) { frmShowF.listViewEx1.Columns.Add(ipTable.Fields.get_Field(j).Name); } for (int i = 0; i < count; i++) { frmShowF.listViewEx1.Items.Add(ipTable.GetRow(i).OID.ToString()); frmShowF.listViewEx1.Items.SubItems.Add(strGeoType); for (int j = 2; j < ipTable.Fields.FieldCount; j++) { frmShowF.listViewEx1.Items.SubItems.Add(ipTable.GetRow(i).get_Value(j).ToString()); } } frmShowF.Owner = this; frmShowF.TopLevel = true; frmShowF.Show(); //Marshal.ReleaseComObject(ipLyr); Marshal.ReleaseComObject(ipFLayer); Marshal.ReleaseComObject(ipTable); } } catch (Exception ee) { MessageBoxEx.Show(ee.Message); } 二、采用IFDOToADOConnection 绑定数据到DataGriView( 这个方法其实有个问题,对于有空间属性的Shp文件来说,DataGridView是显示不了Shape这个字段的,不过我们要看的是属性信息,可以把这个字段剔除,如果谁有方法能够解决这个问题,请告知我吧,谢谢哦) ILayer ipLyr = GetLayerByName(layer.Name); IFeatureLayer ipFLayer = ipLyr as IFeatureLayer; ITable ipTable = ipFLayer as ITable; int count = ipTable.RowCount(null); if (count == 0) { MessageBoxEx.Show("该图层无实体数据可查询"); return; } frmShowFeatures frmShowF = new frmShowFeatures(ipLyr, mapControl); frmShowF.lblFeaCount.Text = "该图层共有" + count.ToString() + "个要素"; IFeatureClass ipFClass = ipFLayer.FeatureClass; IDataset ipDataset = ipFClass as IDataset; IWorkspace ipWS = ipDataset.Workspace; IFDOToADOConnection fdoToadoConnection = new FdoAdoConnectionClass(); //ADODB.Connection adoConnection = (ADODB.Connection)fdoToadoConnection.CreateADOConnection(ipWS); ADODB.Connection adoConnection = new ADODB.Connection(); fdoToadoConnection.Connect(ipWS, adoConnection); ADODB.Recordset adoRecordSet = new ADODB.Recordset(); adoRecordSet.Open("Select FID,Area,x,y from " + layer.Name, adoConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, 0); OleDbDataAdapter custDA = new OleDbDataAdapter(); DataTable dtTerritories = new DataTable("Territories"); custDA.Fill(dtTerritories, adoRecordSet); dataGridView1.DataSource = dtTerritories; adoConnection.Close(); adoRecordSet.Close(); adoConnection = null; adoRecordSet = null; |