2.8. Mapping .NET Data Provider Data Types to .NET Framework Data Types
Problem
You want to convert between .NET provider data types and .NET Framework data types.
Solution
You need to understand the .NET Framework data types; their mappings
to SQL Server, OLE DB, ODBC, and Oracle data types; and how to
properly cast them. The .NET Framework typed accessors and .NET
Framework provider-specific typed accessors for use with the
DataReader
class are also important.
Discussion
The ADO.NET DataSet
and contained objects are data
source independent. The DataAdapter
is used to
retrieve data into the DataSet
and to reconcile
modifications made to the data to the data source at some later time.
The implication is that data in the DataTable
objects contained in the DataSet
are .NET
Framework data types rather than data types specific to the
underlying data source or the .NET data provider used to connect to
that data source.
While the DataReader
object for a data source is
specific to the .NET data provider used to retrieve the data, the
values in the DataReader
are stored in variables
with .NET Framework data types.
The .NET Framework data type is inferred from the .NET data provider
used to fill the DataSet
or build the
DataReader
. The DataReader
has typed accessor methods that improve performance by returning a value as a specific .NET Framework data type when the data type is known, thereby eliminating the need for additional type conversion. For more information about using typed accessors ...
Get ADO.NET 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.