TAILIEUCHUNG - An Example of Using the Get* Methods phần 1

An Example of Using the Get* Methods Let's take a look at an example that reads the ProductID, ProductName, UnitPrice, UnitsInStock, and Discontinued columns from the Products table using the Get* methods. | An Example of Using the Get Methods Let s take a look at an example that reads the ProductID ProductName UnitPrice UnitsInStock and Discontinued columns from the Products table using the Get methods. To figure out which Get method to use to retrieve a particular SQL Server column type you use Table shown earlier. For example the ProductID column is a SQL Server int and looking up that SQL Server type in Table you can see you use the GetInt32 method to obtain the column value as a C int. Table summarizes the column names SQL Server types Get methods and C return types required to retrieve the five columns from the Products table. Table Products TABLE COLUMNS TYPES AND METHODS COLUMN NAME SQL SERVER COLUMN TYPE GET METHOD C RETURN TYPE ProductID int GetInt32 int ProductName nvarchar GetString string UnitPrice money GetDecimal decimal UnitsInStock smallint GetInt16 short Discontinued bit GetBoolean bool Let s assume that you already have a SqlDataReader object named productsSqlDataReader and that it may be used to read the five columns from the Products table. The following while loop uses the Get methods and returned C types shown in Table to obtain the column values from productsSqlDataReader while int productID productIDColPos productID productID string productName productNameColPos productName productName decimal unitPrice unitPriceColPos unitPrice unitPrice short unitsInStock unitsInStockColPos unitsInStock unitsInStock bool discontinued discontinuedColPos discontinued discontinued As you can see five variables of the appropriate type are created in this while loop each of which is used to store the result from the Get method. For example the productID variable is used to

TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.