![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Mapping .NET Data Provider Data Types to .NET Framework Data Types
Số trang: 7
Loại file: pdf
Dung lượng: 44.94 KB
Lượt xem: 1
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ Team LiB ] Recipe 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
Nội dung trích xuất từ tài liệu:
Mapping .NET Data Provider Data Types to .NET Framework Data Types[ Team LiB ]Recipe 2.8 Mapping .NET Data Provider Data Types to .NET Framework DataTypesProblemYou want to convert between .NET provider data types and .NET Framework data types.SolutionYou 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 .NETFramework typed accessors and .NET Framework provider-specific typed accessors foruse with the DataReader class are also important.DiscussionThe ADO.NET DataSet and contained objects are data source independent. TheDataAdapter is used to retrieve data into the DataSet and to reconcile modifications madeto the data to the data source at some later time. The implication is that data in theDataTable objects contained in the DataSet are .NET Framework data types rather thandata types specific to the underlying data source or the .NET data provider used toconnect to that data source.While the DataReader object for a data source is specific to the .NET data provider usedto retrieve the data, the values in the DataReader are stored in variables with .NETFramework data types.The .NET Framework data type is inferred from the .NET data provider used to fill theDataSet or build the DataReader. The DataReader has typed accessor methods thatimprove performance by returning a value as a specific .NET Framework data type whenthe data type is known, thereby eliminating the need for additional type conversion. Formore information about using typed accessors with a DataReader, see Recipe 9.6.Some DataReader classes expose data source specific accessor methods as well. Forexample, the SqlDataReader exposes accessor methods that return SQL Server data typesas objects of System.Data.SqlType.The following example shows how to cast a value from a DataReader to a .NETFramework data type and how to use the .NET Framework typed accessor and the SQLServer-specific typed accessor:// Create the connection and the command.SqlConnection conn = new SqlConnection( ConfigurationSettings.AppSettings[Sql_ConnectString]);SqlCommand cmd = new SqlCommand( SELECT CategoryID, CategoryName FROM Categories, conn);// Open the connection and build the DataReader.conn.Open( );SqlDataReader dr = cmd.ExecuteReader( );// Get the CategoryID from the DataReader and cast to int.int categoryId = Convert.ToInt32(dr[0]);// Get the CategoryID using typed accessor.int taCategoryId = dr.GetInt32(0);// Get the CategoryID using the SQL Server-specific accessor.System.Data.SqlTypes.SqlInt32 sqlCategoryId = dr.GetSqlInt32(0);In all cases, a null value for a .NET Framework data type is represented bySystem.DBNull.Value.Table 2-7 lists the inferred .NET Framework data type, the .NET Framework typedaccessor for the DataReader, and the SQL Server-specific typed accessor for each SQLServer data type. Table 2-7. Data types and accessors for SQL Server .NET data provider SQL Server data .NET Framework .NET Framework SQLType typed type data type typed accessor accessorbigint Int64 GetInt64( ) GetSqlInt64( )binary Byte[] GetBytes( ) GetSqlBinary( )bit Boolean GetBoolean( ) GetSqlBit( ) GetString( )GetChars(char StringChar[] GetSqlString( ) )datetime DateTime GetDateTime( ) GetSqlDateTime( )decimal Decimal GetDecimal( ) GetSqlDecimal( )float Double GetDouble( ) GetSqlDouble( )image Byte[] GetBytes( ) GetSqlBinary( )int Int32 GetInt32( ) GetSqlInt32( )money Decimal GetDecimal( ) GetSqlMoney( ) GetString( )GetChars(nchar StringChar[] GetSqlString( ) ) GetString( )GetChars(ntext StringChar[] GetSqlString( ) )numeric Decimal GetDecimal( ) GetSqlDecimal( ) GetString( )GetChars(nvarchar StringChar[] GetSqlString( ) )real Single GetFloat( ) GetSqlSingle( )smalldatetime DateTime GetDateTime( ) GetSqlDateTime( )smallint Int16 GetInt16( ) GetSqlInt16( )smallmoney Decimal GetDecimal( ) GetSqlDecimal( )sql_variant Object GetValue( ) GetSqlValue( ) GetString( )GetChars(text StringChar[] GetSqlString( ) )timestamp Byte[] GetBytes( ) GetSqlBinary( )tinyint Byte GetByte( ) GetSqlByte( )uniqueidentifier Guid GetGuid( ) GetSqlGuid( )varbinary Byte[] GetBytes( ) GetSqlBinary( ) GetString( )GetChars(varchar StringChar[] GetSqlString( ) )Table 2-8 lists the inferred . ...
Nội dung trích xuất từ tài liệu:
Mapping .NET Data Provider Data Types to .NET Framework Data Types[ Team LiB ]Recipe 2.8 Mapping .NET Data Provider Data Types to .NET Framework DataTypesProblemYou want to convert between .NET provider data types and .NET Framework data types.SolutionYou 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 .NETFramework typed accessors and .NET Framework provider-specific typed accessors foruse with the DataReader class are also important.DiscussionThe ADO.NET DataSet and contained objects are data source independent. TheDataAdapter is used to retrieve data into the DataSet and to reconcile modifications madeto the data to the data source at some later time. The implication is that data in theDataTable objects contained in the DataSet are .NET Framework data types rather thandata types specific to the underlying data source or the .NET data provider used toconnect to that data source.While the DataReader object for a data source is specific to the .NET data provider usedto retrieve the data, the values in the DataReader are stored in variables with .NETFramework data types.The .NET Framework data type is inferred from the .NET data provider used to fill theDataSet or build the DataReader. The DataReader has typed accessor methods thatimprove performance by returning a value as a specific .NET Framework data type whenthe data type is known, thereby eliminating the need for additional type conversion. Formore information about using typed accessors with a DataReader, see Recipe 9.6.Some DataReader classes expose data source specific accessor methods as well. Forexample, the SqlDataReader exposes accessor methods that return SQL Server data typesas objects of System.Data.SqlType.The following example shows how to cast a value from a DataReader to a .NETFramework data type and how to use the .NET Framework typed accessor and the SQLServer-specific typed accessor:// Create the connection and the command.SqlConnection conn = new SqlConnection( ConfigurationSettings.AppSettings[Sql_ConnectString]);SqlCommand cmd = new SqlCommand( SELECT CategoryID, CategoryName FROM Categories, conn);// Open the connection and build the DataReader.conn.Open( );SqlDataReader dr = cmd.ExecuteReader( );// Get the CategoryID from the DataReader and cast to int.int categoryId = Convert.ToInt32(dr[0]);// Get the CategoryID using typed accessor.int taCategoryId = dr.GetInt32(0);// Get the CategoryID using the SQL Server-specific accessor.System.Data.SqlTypes.SqlInt32 sqlCategoryId = dr.GetSqlInt32(0);In all cases, a null value for a .NET Framework data type is represented bySystem.DBNull.Value.Table 2-7 lists the inferred .NET Framework data type, the .NET Framework typedaccessor for the DataReader, and the SQL Server-specific typed accessor for each SQLServer data type. Table 2-7. Data types and accessors for SQL Server .NET data provider SQL Server data .NET Framework .NET Framework SQLType typed type data type typed accessor accessorbigint Int64 GetInt64( ) GetSqlInt64( )binary Byte[] GetBytes( ) GetSqlBinary( )bit Boolean GetBoolean( ) GetSqlBit( ) GetString( )GetChars(char StringChar[] GetSqlString( ) )datetime DateTime GetDateTime( ) GetSqlDateTime( )decimal Decimal GetDecimal( ) GetSqlDecimal( )float Double GetDouble( ) GetSqlDouble( )image Byte[] GetBytes( ) GetSqlBinary( )int Int32 GetInt32( ) GetSqlInt32( )money Decimal GetDecimal( ) GetSqlMoney( ) GetString( )GetChars(nchar StringChar[] GetSqlString( ) ) GetString( )GetChars(ntext StringChar[] GetSqlString( ) )numeric Decimal GetDecimal( ) GetSqlDecimal( ) GetString( )GetChars(nvarchar StringChar[] GetSqlString( ) )real Single GetFloat( ) GetSqlSingle( )smalldatetime DateTime GetDateTime( ) GetSqlDateTime( )smallint Int16 GetInt16( ) GetSqlInt16( )smallmoney Decimal GetDecimal( ) GetSqlDecimal( )sql_variant Object GetValue( ) GetSqlValue( ) GetString( )GetChars(text StringChar[] GetSqlString( ) )timestamp Byte[] GetBytes( ) GetSqlBinary( )tinyint Byte GetByte( ) GetSqlByte( )uniqueidentifier Guid GetGuid( ) GetSqlGuid( )varbinary Byte[] GetBytes( ) GetSqlBinary( ) GetString( )GetChars(varchar StringChar[] GetSqlString( ) )Table 2-8 lists the inferred . ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Mapping .NET Data Provider Data Types to .NET Framework Data TypesTài liệu liên quan:
-
52 trang 442 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 332 0 0 -
74 trang 311 0 0
-
96 trang 307 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 300 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 294 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 291 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 280 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 275 0 0