Danh mục

Using the Get* Methods to Read Column Values

Số trang: 3      Loại file: pdf      Dung lượng: 26.80 KB      Lượt xem: 2      Lượt tải: 0    
Thu Hiền

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Using the Get* Methods to Read Column Values Before I show you the other Get* methods that read column values, you need to know the standard C# types and the values they support
Nội dung trích xuất từ tài liệu:
Using the Get* Methods to Read Column ValuesUsing the Get* Methods to Read Column ValuesBefore I show you the other Get* methods that read column values, you need to know thestandard C# types and the values they support. You need to know these so that you canunderstand the type compatibilities between C# and SQL Server shown later. Table 9.3shows the standard C# types, along with the underlying .NET type and the values that canbe stored in the C# type. Table 9.3: STANDARD C# AND .NET TYPESC# .NET VALUESTYPE TYPEbool Boolean A Boolean true or false value.byte Byte An 8-bit unsigned integer between 0 and 28 - 1(255).char Char A 16-bit Unicode character.DateTime DateTime A date and time between 12:00:00 AM January 1, 0001 and 11:59:59 PM December 31, 9999.decimal Decimal A fixed precision and scale number between approximately +/-1.0 *10-28 and approximately +/-7.9 *1028 with 28 significant figures of precision.double Double A 64-bit floating-point number between approximately +/-5 *10- 324 and approximately +/-1.7 *10308 with 15 to 16 significant figures of precision.float Single A 32-bit floating-point number between approximately +/-1.5 *10- 45 to approximately +/-3.4 *1038 with 7 significant figures of precision.Guid Guid A 128-bit unsigned integer value (16 bytes) that that is unique across all computers and networks.int Int32 A 32-bit signed integer between -231 (-2,147,483,648) and 231 - 1 (2,147,483,647).long Int64 A 64-bit signed integer between -263 (- 9,223,372,036,854,775,808) and 263 - 1 (9,223,372,036,854,775,807).sbyte SByte An 8-bit signed integer between -27 (-128) and 27 - 1 (127).short Int16 A 16-bit signed integer between -215 (-32,768) and 215 - 1 (32,767).string String A variable-length string of 16-bit Unicode characters. Table 9.3: STANDARD C# AND .NET TYPESC# .NET VALUESTYPE TYPEuint UInt32 A 32-bit unsigned integer between 0 and 232 - 1 (4,294,967,295).ulong UInt64 A 64-bit unsigned integer between 0 and 264 - 1 (18,446,744,073,709,551,615).ushort UInt16 A 16-bit unsigned integer between 0 and 216 - 1 (65,535).Note The standard C# types are defined in the System namespace.Table 9.4 shows the SQL Server types, the compatible standard C# types, and theDataReader Get* methods that return each C# type. You use this table to figure out whichmethod to call to get a specific column type. For example, if you need to get the value ofa bigint column, you call the GetInt64() method that returns a long. Table 9.4: SQL SERVER TYPES, COMPATIBLE STANDARD C# TYPES, AND GET* METHODSSQL SERVER TYPE COMPATIBLE STANDARD C# TYPE GET* METHODbinary byte[] GetBytes()bigint long GetInt64()bit bool GetBoolean()char string GetString()datetime DateTime GetDateTime()decimal decimal GetDecimal()float double GetDouble()image byte[] GetBytes()int int GetInt32()money decimal GetDecimal()nchar string GetString()ntext string GetString()nvarchar string GetString()numeric decimal GetDecimal()real float GetFloat()smalldatetime DateTime GetDateTime()smallint short GetInt16()smallmoney decimal GetDecimal() Table 9.4: SQL SERVER TYPES, COMPATIBLE STANDARD C# TYPES, AND GET* METHODSSQL SERVER TYPE COMPATIBLE STANDARD C# TYPE GET* METHODsql_varient object GetValue()text string GetString()timestamp byte[] GetBytes()tinyint byte GetByte()varbinary byte[] GetBytes()varchar string GetString()uniqueidentifier Guid GetGuid()Note You can see the SQL Server types and the values supported by those types in Table 2.3 of Chapter 2, Introduction to Databases.Note The Get* methods are defined in all of the DataReader classes and work for all databases.Next youll see how to use some of the methods shown in Table 9.4.

Tài liệu được xem nhiều: