Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Map Data-Source Columns to Dataset Data-Table Columns 

Creating a mapping in a data adapter allows you to establish a correspondence between columns in the data source and columns in a dataset table. For more information, see Table Mapping in Data Adapters.

NoteNote

In the previous version of Visual Studio, data adapters were used for communicating between an application and a database. While data adapters are still a main component of .NET Framework Data Providers, TableAdapters are designer-generated components that simplify the process of moving data between your application and a database. For more information on working with TableAdapters, see TableAdapter Overview.

To map data-source columns to a dataset table

  1. Create a data adapter. For more information, see Creating Data Adapters.

  2. In a form or component designer, select the data adapter and open the Properties window.

  3. Next to the TableMappings property, click the ellipsis (...) button. The Table Mappings dialog box opens.

  4. If you want to map column names from the data source to an existing dataset, check Use a Dataset to suggest table and column names, and then select a dataset from the Dataset list.

    The tables available in that dataset are listed in the Dataset table list, and the columns of the first table in the dataset are filled into the right-hand side of the Column mappings grid.

    NoteNote

    Choosing a dataset is a convenience that allows the Mappings dialog box to establish defaults for the dataset columns to map to. The dataset is not part of the information maintained for the mappings in the adapter. Moreover, you might use the same mappings with more than one dataset.

  5. Under Source table, select the table in the data source to map. If there is only one table in the dataset, the default value is Table.

  6. Under Dataset table, select the table in the dataset to map. If you selected a dataset to map to in Step 3, a name will already be filled in. (By default, the first table in the dataset is referred to as Table.)

    Based on your choices (or the defaults), values in the Source Columns and Dataset Columns lists are filled in. The grid indicates how mapping will be performed: each column in the left-hand column will be matched to the corresponding column in the right-hand column.

  7. Adjust the mappings as needed. This can include:

    • Selecting different columns in either the source or dataset column lists to change which columns map to which.

    • Removing columns from the mapping. You might do this if the adapter is returning more columns from the data source than what you need.

    • Adding columns. You might do this if you know that columns will exist at run time that are not represented at design time, or if you deleted a column and now want it back, or if you refined the adapter's query and now need to adjust the mappings.

  8. When you have finished adjusting the mappings, click OK.

  9. If you want to specify how to handle possible error conditions, in the Properties window, select options for the MissingMappingAction and MissingSchemaAction properties. The following table lists some common settings and their effect.

    MissingMappingAction MissingSchemaAction Effect

    Passthrough

    Add or AddWithKey

    If a column exists in the source but not in the schema and there is no mapping for it, the column is created when the dataset is filled. This is the default setting, and is useful when you simply want to copy all the columns available in the source to the dataset.

    Ignore

    Ignore

    If the column is not defined in the dataset schema, or if there is no mapping for it, information is not copied from the source to the dataset. This setting is useful if the adapter returns more information than you want in the dataset.

    Error

    Error

    A run-time error is raised if the adapter cannot map a source column to a dataset column because the mapping is missing or because the dataset schema does not contain the column. This setting is useful when you are working with a stringently defined schema and want to be sure that any deviations from the schema are flagged.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft