LinkData method

Links data as a DataSet object; similar to the Link Data Wizard. Linked sets can be updated when the source data has changed.

Applies to

Collections:  DataSets

Syntax

Click a parameter to jump to its description below.

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

Parameters

Part Description
object Required. An expression that returns a DataSets collection.
DataSourceMoniker Required String. File name to link to. Can also provide information on which part of the file to link to. See the DataSourceMoniker syntax topic for the correct syntax to use for this parameter.
PrimaryKeyField Required Variant. Key field in the data file. Can be either the field name or the ordinal. Is always linked to, whether it is listed in ArrayOfFields or not. Must be a unique field of values (for example, customer number or order number).
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 link. If a Field object is not listed in the array, then it is given a GeographicFieldType property of geoFieldSkipped (except for the PrimaryKeyField, which is always linked).

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 linked.

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 linking to 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 Link Data Wizard for user input, use the ShowLinkWizard method on the DataSets collection.

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

Example

  [Visual Basic 6.0]
Sub LinkToMultipleSources()
  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 = .LinkData(szconn, "ID", , geoCountryUnitedStates, geoDelimiterTab)
    'CSV text file     szconn = objApp.Path & "\Samples\Sales.csv"     Set oDS = .LinkData(szconn,"ID", , geoCountryUnitedStates, geoDelimiterComma)
    'Access database with a table     szconn = objApp.Path & "\Samples\Clients.mdb!Addressestable"     Set oDS = .LinkData(szconn,"ID", , geoCountryUnitedStates, , geoImportAccessTable)
    'Access database with a query     szconn = objApp.Path & "\Samples\Clients.mdb!AddressQuery"     Set oDS = .LinkData(szconn,"ID", , geoCountryUnitedStates, , geoImportAccessQuery)
    'Excel sheet     szconn = objApp.Path & "\Samples\Sales.xls!Sheet1!A1:D3"     Set oDS = .LinkData(szconn,"ID", , geoCountryUnitedStates, , geoImportExcelA1)
    'Excel sheet R1C1 reference     szconn = objApp.Path & "\Samples\Sales.xls!Sheet1!R1C1:R3C9"     Set oDS = .LinkData(szconn,"ID", , geoCountryUnitedStates, , geoImportExcelR1C1)
    'Excel sheet named range     szconn = objApp.Path & "\Samples\SampData.xls!First10Clients"     Set oDS = .LinkData(szconn,"F1", , geoCountryUnitedStates, , geoImportExcelNamedRange)   End With
End Sub
[C#]
void LinkToMultipleSources() { 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.LinkData(szconn, "ID",Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterTab, 0); //CSV text file szconn = objApp.Path + "\\Samples\\Sales.csv"; oDS = objDSS.LinkData(szconn, "ID", Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterComma, 0); //Access database with a table szconn = objApp.Path + "\\Samples\\Clients.mdb!Addressestable"; oDS = objDSS.LinkData(szconn, "ID",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.LinkData(szconn, "ID",Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportAccessQuery); //Excel sheet szconn = objApp.Path + "\\Samples\\Sales.xls!Sheet1"; oDS = objDSS.LinkData(szconn, "ID",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.LinkData(szconn, "ID", Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportExcelR1C1); //Excel sheet named range szconn = objApp.Path + "\\Samples\\SampData.xls!First10Clients"; oDS = objDSS.LinkData(szconn, "F1",Type.Missing, MapPoint.GeoCountry.geoCountryUnitedStates, MapPoint.GeoDelimiter.geoDelimiterDefault, MapPoint.GeoImportFlags.geoImportExcelNamedRange); }

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