| title | SqlTypes and the DataSet | |
|---|---|---|
| description | Describes type support for SqlTypes in the DataSet. | |
| author | David-Engel | |
| ms.author | v-davidengel | |
| ms.reviewer | v-kaywon | |
| ms.date | 08/15/2019 | |
| ms.service | sql | |
| ms.subservice | connectivity | |
| ms.topic | conceptual | |
| dev_langs |
|
[!INCLUDEDriver_ADONET_Download]
ADO.NET 2.0 introduced enhanced type support for the DataSet through the xref:System.Data.SqlTypes namespace. The types in xref:System.Data.SqlTypes are designed to provide data types with the same semantics and precision as the data types in a SQL Server database. Each data type in xref:System.Data.SqlTypes has an equivalent data type in SQL Server, with the same underlying data representation.
Using xref:System.Data.SqlTypes directly in a xref:System.Data.DataSet confers several benefits when working with SQL Server data types. xref:System.Data.SqlTypes supports the same semantics as SQL Server native data types. Specifying one of the xref:System.Data.SqlTypes in the definition of a xref:System.Data.DataColumn eliminates the loss of precision that can occur when converting decimal or numeric data types to one of the common language runtime (CLR) data types.
The following example creates a xref:System.Data.DataTable object, explicitly defining the xref:System.Data.DataColumn data types by using xref:System.Data.SqlTypes instead of CLR types. The code fills the xref:System.Data.DataTable with data from the Sales.SalesOrderDetail table in the AdventureWorks database in SQL Server. The output displayed in the console window shows the data type of each column, and the values retrieved from SQL Server.
[!code-csharpDataWorks DataColumn_DataType#1]