'Excel 2007 Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\MyExcelSpreadsheet.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes""") Dim objCmdSelect As OleDbCommand = New OleDbCommand(expr, ExcelConnection) Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter() Dim objDT As DataTable Dim ds As New DataSet() Using objCmdSelect objCmdSelect.Connection = ExcelConnection objAdapter1.SelectCommand = objCmdSelect objAdapter1.Fill(ds, "dtExcelData") End Using objDT = ds.Tables(0) Dim ct As Integer ct = objDT.Rows.Count 'make sure the DataTable was filled with rows
Dim pFeatCur As IFeatureCursor Dim pFeatBuf As IFeatureBuffer pFeatBuf = pFeatureClass.CreateFeatureBuffer pFeatCur = pFeatureClass.Insert(True) Dim dtCol As DataColumn Dim dtColname As String Dim row As DataRow For i = 0 To objDT.Rows.Count - 1 row = objDT.Rows(i) '***add the rest of the attributes For Each dtCol In objDT.Columns dtColname = dtCol.ColumnName.ToString Dim dtColType As String = dtCol.DataType.ToString If Not IsDBNull(row.Item(dtColname)) Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = row.Item(dtColname) Else If dtCol.DataType.FullName.ToString = "System.Int32" Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CInt(0) ElseIf dtCol.DataType.FullName.ToString = "System.String" Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CStr("NA") ElseIf dtCol.DataType.FullName.ToString = "System.Double" Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDbl(0.0) ElseIf dtCol.DataType.FullName.ToString = "System.Decimal" Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDec(0.0) ElseIf dtCol.DataType.FullName.ToString = "System.DateTime" Then pFeatBuf.Value(pFeatBuf.Fields.FindField(dtColname)) = CDate(Now()) End If End If Next pFeatCur.InsertFeature(pFeatBuf) Else End If Next pFeatCur.Flush()
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.