Improving DataReader Performance with Column Ordinals

[ Team LiB ] Recipe Improving DataReader Performance with Column Ordinals Problem You want to use column ordinals rather than column names to retrieve data from a DataReader to improve application performance and without hard-coding | Team LiB Recipe Improving DataReader Performance with Column Ordinals Problem You want to use column ordinals rather than column names to retrieve data from a DataReader to improve application performance and without hard-coding the ordinal values. Solution Enumerate the column ordinals using the GetOrdinal method and use those values to retrieve data from the DataReader. The sample code contains two event handlers Sets up the sample by using a DataReader to retrieve the ordinals for all columns in the Orders table of the Northwind database. Go Builds a new DataReader containing the TOP 5 records from the Orders table in the Northwind database. The code iterates over the records in the DataReader and demonstrates techniques to retrieve data from the OrderlD CustomerlD OrderDate and ShipRegion using accessors that are index-based nonspecific provider-specific nonspecific with null check and provider-specific with null check. The C code is shown in Example 9-11. Example 9-11. File Namespaces variables and constants using System using using using using private int co_OrderId private int co_CustomerId private int co_EmployeeId private int co_OrderDate private int co_RequiredDate private int co_ShippedDate private int co_ShipVia private int co_Freight private int co_ShipName private int co_ShipAddress private int co_ShipCity private int co_ShipRegion private int co_ShipPostalCode private int co_ShipCountry . . . private void OptimizingDataRetrievalDataReaderForm_Load object sender e String sqlText SELECT FROM Orders Create the connection and command. SqlConnection conn new SqlConnection S ql_ConnectString SqlCommand cmd new SqlCommand sqlText conn Create the DataReader to retrieve ordinals. SqlDataReader dr Retrieve the column ordinals for .

Bấm vào đây để xem trước nội dung
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.