Use Column and Table Mappings

Problem

You want to map database column and table names to the names expected by your code for the DataSet.

Solution

Create ColumnMapping objects for each column and DataTableMapping objects for each table, and assign them to the DataAdapter.TableMappings collection.

Discussion

The DataAdapter provides a layer of indirection between the data source and the DataSet. Using the DataAdapter, you can configure table and column mappings so that code remains unchanged when the data source changes (or vice versa).

Column mappings link a field in the data source with a differently named field in the DataSet. The following example shows how you might modify names in the Categories table when filling a DataSet: Source fields like ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.