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 基底類型的實值型別 (Value Type) 和參考型別 (Reference Type)。It consists of both value types and reference types, which all derive from the Object base type. 使用資料來源時,如果沒有明確指定資料型別,就會從資料提供者 (Data Provider) 推斷資料型別。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 Data Provider 特定的類型。用來連接到資料來源。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. 針對的Fill DataAdapter 作業Get和的方法,會從.NETFrameworkDataProvider傳回的值推斷.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 Data Provider 資料類型的 Null 值會以表示DBNull.ValueNull 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
說明開發人員在使用浮點數值 (Floating-Point Number) 時經常遇到的問題。Describes issues that developers frequently encounter when working with floating-point numbers.

另請參閱See also