Share via


ImportData method

Imports data as a DataSet object; similar to the Import Data Wizard.

Applies to

Collections:  DataSets

Syntax

Click a parameter to jump to its description below.

object .ImportData(DataSourceMoniker, [ArrayOfFields], [Country], [Delimiter], [ImportFlags])

Parameters

Part Description
object Required. An expression that returns a DataSets collection.
DataSourceMoniker Required String. File name to import. Can also provide information on which part of the file to import. See the DataSourceMoniker syntax topic for the correct syntax to use for this parameter.
ArrayOfFields Optional Variant. A two-column array:

The first column contains the field name or an integer representing the field index (which starts at 1) of each field to import. If a Field object is not listed in the array, then it is given a GeographicFieldType property of geoFieldSkipped.

The second column designates one of three ways to treat the record:

Use a GeoFieldType value, which MapPoint will geocode (see GeoFieldType values for a list of values and their descriptions).

Use a string, which MapPoint will interpret as the field name for geoFieldData.

Leave blank to have MapPoint determine the field's contents and title.

If this parameter is not supplied, then all fields in the data source are imported.

Country Optional GeoCountry. Country associated with the data. Default is geoCountryDefault. See the GeoCountry values topic for a list of GeoCountry values and their descriptions.
Delimiter Optional GeoDelimiter. Characters that separate individual fields. Can be one or more characters. Required for importing text files. Default is geoDelimiterDefault.
GeoDelimiter Value Description
geoDelimiterComma
44
Fields separated by commas (","). Default for .csv files.
geoDelimiterDefault
0
MapPoint determines the delimiter based on the file type.
File type Default Delimiter
.asc tab
.csv comma
.tab tab
.txt tab
geoDelimiterSemicolon
59
Fields separated by semicolons.
geoDelimiterTab
9
Fields separated by tabs ("\t"). Default for .tab, .txt, and .asc files.
ImportFlags Optional Long. Provides information about the DataSourceMoniker and the data in the file. Multiple values can be passed by using the Microsoft Visual Basic "Or" operator (for example, geoImportExcelNamedRange Or geoImportFirstRowIsNotHeadings).
GeoImportFlags Value Description
geoImportAccessQuery
4
DataSourceMoniker specifies an Access query.
geoImportAccessTable
0
DataSourceMoniker specifies an Access table. Default.
geoImportExcelA1
0
DataSourceMoniker specifies Excel A1 syntax. Default.
geoImportExcelNamedRange
4
DataSourceMoniker specifies an Excel named range.
geoImportExcelR1C1
2
DataSourceMoniker specifies Excel R1C1 syntax.
geoImportExcelSheet
0
DataSourceMoniker specifies an Excel worksheet. Default.
geoImportFirstRowIsHeadings
0
First row of the file contains field names. Default.
geoImportFirstRowNotHeadings
1
First row of the file does not contain field names.

Remarks

To open the Import Data Wizard for user input, use the ShowImportWizard method on the DataSets collection.

To learn more about mapping data, see the Getting started with data sets and data mapping reference topic.

Example

Importing data from various sources

  [Visual Basic 6.0]
Sub ImportFromMultipleSources()
  Dim objApp As New MapPoint.Application   objApp.Visible = True   objApp.UserControl = True   Dim szconn As String   Dim oDS As MapPoint.DataSet
  With objApp.ActiveMap.DataSets     'Text file with tab     szconn = objApp.Path & "\Samples\Sales.txt"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, geoDelimiterTab)
    'CSV text file     szconn = objApp.Path & "\Samples\Sales.csv"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, geoDelimiterComma)
    'Access database with a table     szconn = objApp.Path & "\Samples\Clients.mdb!Addressestable"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, , geoImportAccessTable)
    'Access database with a query     szconn = objApp.Path & "\Samples\Clients.mdb!AddressQuery"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, , geoImportAccessQuery)
    'Excel sheet     szconn = objApp.Path & "\Samples\Sales.xls!Sheet1"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, , geoImportExcelSheet)
    'Excel sheet R1C1 reference     szconn = objApp.Path & "\Samples\Sales.xls!Sheet1!R1C1:R3C9"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, , geoImportExcelR1C1)
    'Excel sheet named range     szconn = objApp.Path & "\Samples\SampData.xls!First10Clients"     Set oDS = .ImportData(szconn, , geoCountryUnitedStates, , geoImportExcelNamedRange)   End With
End Sub
[C#]
void ImportFromMultipleSources() { MapPoint.ApplicationClass objApp = new MapPoint.ApplicationClass(); objApp.Visible = true; objApp.UserControl = true; string szconn; MapPoint.DataSet oDS; MapPoint.DataSets objDSS = objApp.ActiveMap.DataSets; //Text file with tab szconn = objApp.Path + "\\Samples\\Sales.txt"; oDS = objDSS.ImportData(szconn,Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterTab, 0); //CSV text file szconn = objApp.Path + "\\Samples\\Sales.csv"; oDS = objDSS.ImportData(szconn, Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterComma, 0); //Access database with a table szconn = objApp.Path + "\\Samples\\Clients.mdb!Addressestable"; oDS = objDSS.ImportData(szconn, Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportAccessTable); //Access database with a query szconn = objApp.Path + "\\Samples\\Clients.mdb!AddressQuery"; oDS = objDSS.ImportData(szconn,Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportAccessQuery); //Excel sheet szconn = objApp.Path + "\\Samples\\Sales.xls!Sheet1"; oDS = objDSS.ImportData(szconn,Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportExcelSheet); //Excel sheet R1C1 reference szconn = objApp.Path + "\\Samples\\Sales.xls!Sheet1!R1C1:R3C9"; oDS = objDSS.ImportData(szconn, Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportExcelR1C1); //Excel sheet named range szconn = objApp.Path + "\\Samples\\SampData.xls!First10Clients"; oDS = objDSS.ImportData(szconn, Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportExcelNamedRange); }

Note  This sample code is specific for use in MapPoint North America; it is for illustration purposes only.

Using the ArrayOfFields parameter

  
    Sub ImportFromMultipleSources()
  Dim mpApp As MapPoint.Application   Dim mpDatasets As MapPoint.DataSets   Dim mpDataSet As MapPoint.DataSet   Dim myExampleArray(4, 2)
  'Start MapPoint   Set mpApp = New MapPoint.Application   mpApp.Visible = True   mpApp.UserControl = True
  'Get the DataSets collection   Set mpDatasets = mpApp.NewMap.DataSets
  'Create the ArrayOfFields descriptions
  'Field is specified by name    myExampleArray(1, 1) = "Latitude"   'tells MapPoint to use this field as the latitude field    myExampleArray(1, 2) = geoFieldLatitude
  'Field again specifed by name   myExampleArray(2, 1) = "Longitude"   'tells MapPoint to use this field as the longitude field   myExampleArray(2, 2) = geoFieldLongitude
  'Field is listed by index, rather than name   myExampleArray(3, 1) = 1   'tells MapPoint to use this field as additional (non geocoding) information    myExampleArray(3, 2) = geoFieldData
  'Field is specified by source name    myExampleArray(4, 1) = "ExDat"   'New field name after import--when changing the name,   'MapPoint assumes that the type is geoFieldData   myExampleArray(4, 2) = "ExampleData"
  'Perform the import   Set mpDataSet = mpDatasets.ImportData("c:\foo.xls!Sheet1!A1:B4", myExampleArray)
  'The (x,2) elements are of the type GeoFieldType or string.   'If string, then they set the new name of the field, and   'MapPoint assumes that the field is a nongeocoding data field.
End Sub

Note  This code is for illustration purposes only; it will not run as-is.