Private Function ConvertToADONETDataTableFromLayer(ByVal inLayer As IFeatureLayer) As DataTable Dim tmpDT As New DataTable("tmpDT") Dim column As DataColumn Dim pTable As ITable = inLayer.FeatureClass Dim pFields As IFields = pTable.Fields Dim pCur As ICursor = pTable.Search(Nothing, False) For c = 0 To pCur.Fields.FieldCount - 1 column = New DataColumn() column.ColumnName = (pFields.Field(c).Name) If pFields.Field(c).Type = esriFieldType.esriFieldTypeString Then column.DataType = System.Type.GetType("System.String") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeInteger Then column.DataType = System.Type.GetType("System.Int32") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDouble Then column.DataType = System.Type.GetType("System.Double") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDate Then column.DataType = System.Type.GetType("System.DateTime") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeSingle Then column.DataType = System.Type.GetType("System.Single") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeBlob Then column.DataType = System.Type.GetType("System.Byte") End If column.ReadOnly = False tmpDT.Columns.Add(column) Next Dim pRow As IRow = pCur.NextRow Dim newRow As DataRow Do Until pRow Is Nothing newRow = tmpDT.NewRow() newRow.BeginEdit() For cols = 0 To pCur.Fields.FieldCount - 1 newRow(cols) = pRow.Value(pRow.Fields.FindField(pFields.Field(cols).Name)) Next newRow.EndEdit() tmpDT.Rows.Add(newRow) tmpDT.AcceptChanges() pRow = pCur.NextRow Loop Return tmpDT End Function
Dim pDoc As IMxDocument Dim pMap As IMap pDoc = m_pApp.Document pMap = pDoc.FocusMap Dim pLayer as IFeatureLayer = pMap.Layer(0) 'just get the first layer for simplicity/example 'Create the ADO.NET DataTable Dim adoDataTable As DataTable = ConvertToADONETDataTableFromLayer(pLayer) 'Setup the ADO.NET Dataset and add the newly created DataTable Dim ds As New DataSet() ds.DataSetName = "dsToConvertToXML" ds.Tables.Add(adoDataTable) 'Now write the DataTable's schema to an .xml file 'remember, this is *really* the schema of the IFeatureLayer because we converted it to an 'ADO.NET DataTable! Dim filename As String = ds.DataSetName.ToString & ".xml" ds.WriteXmlSchema(filename)
Hi ESRI-Forum,I'm looking for a code-sample for exporting the attribute table of a layer to a XML-File. Would be nice, if somebody can send me a hint!Kai
Dim ds As New DataSet() ds.DataSetName = "dsName" Dim filename As String = ds.DataSetName.ToString & ".xml" ds.WriteXmlSchema(filename)
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.