ADO.NET 中的数据类型映射Data Type Mappings in ADO.NET

.NET Framework 基于用于定义如何在运行时声明、使用和管理类型的通用类型系统。The .NET Framework is based on the common type system, which defines how types are declared, used, and managed in the runtime. 它由值类型和引用类型组成,这两种类型均派生自 Object 基类型。It consists of both value types and reference types, which all derive from the Object base type. 使用数据源时,如果未显式指定数据类型,则从数据提供程序推断出它。When working with a data source, the data type is inferred from the data provider if it is not explicitly specified. 例如,DataSet 对象独立于任何特定的数据源。For example, a DataSet object is independent of any specific data source. DataSet 中的数据从数据源中进行检索,而更改则会使用 DataAdapter 持久保存回数据源。Data in a DataSet is retrieved from a data source, and changes are persisted back to the data source by using a DataAdapter. 这意味着当DataAdapter DataSet使用数据源中DataTable的值填充中的时,中列的DataTable结果数据类型为 .NET Framework 类型,而不是特定于 .NET Framework 数据提供程序的类型,用于连接到数据源。This means that when a DataAdapter fills a DataTable in a DataSet with values from a data source, the resulting data types of the columns in the DataTable are .NET Framework types, instead of types specific to the .NET Framework data provider that is used to connect to the data source.

同样,当从DataReader数据源返回值时,生成的值将存储在具有 .NET Framework 类型的局部变量中。Likewise, when a DataReader returns a value from a data source, the resulting value is stored in a local variable that has a .NET Framework type. DataAdapter对于的Fill 操作Get和的方法,将从.NETFramework数据提供程序返回的值推断.NETFramework类型。DataReaderFor both the Fill operations of the DataAdapter and the Get methods of the DataReader, the .NET Framework type is inferred from the value returned from the .NET Framework data provider.

当所返回值的特定类型已知时,可以使用 DataReader 的类型化访问器方法,而不是依靠推断出的数据类型。Instead of relying on the inferred data type, you can use the typed accessor methods of the DataReader when you know the specific type of the value being returned. 类型化访问器方法通过以特定 .NET Framework 类型返回值来提高性能,从而无需额外的类型转换。Typed accessor methods give you better performance by returning a value as a specific .NET Framework type, which eliminates the need for additional type conversion.

备注

.NET Framework 数据提供程序数据类型的 Null 值由DBNull.Value表示。Null values for .NET Framework data provider data types are represented by DBNull.Value.

本节内容In This Section

SQL Server 数据类型映射SQL Server Data Type Mappings
列出针对 System.Data.SqlClient 的推断数据类型映射和数据访问器方法。Lists inferred data type mappings and data accessor methods for System.Data.SqlClient.

OLE DB 数据类型映射OLE DB Data Type Mappings
列出针对 System.Data.OleDb 的推断数据类型映射和数据访问器方法。Lists inferred data type mappings and data accessor methods for System.Data.OleDb.

ODBC 数据类型映射ODBC Data Type Mappings
列出针对 System.Data.Odbc 的推断数据类型映射和数据访问器方法。Lists inferred data type mappings and data accessor methods for System.Data.Odbc.

Oracle 数据类型映射Oracle Data Type Mappings
列出针对 System.Data.OracleClient 的推断数据类型映射和数据访问器方法。Lists inferred data type mappings and data accessor methods for System.Data.OracleClient.

浮点数Floating-Point Numbers
描述开发人员在使用浮点数时经常遇到的问题。Describes issues that developers frequently encounter when working with floating-point numbers.

请参阅See also