TAILIEUCHUNG - Beginning Visual Basic .NET Database Programming phần 6

Các lệnh myCommand dữ liệu được tạo ra bằng cách báo cáo và chuỗi kết nối. Sau đó chúng tôi có thể sử dụng myCommand gây ra DataReader để thực hiện các câu lệnh SQL mà chúng ta muốn - trong trường hợp này, để chọn tất cả hồ sơ từ bảng Sản phẩm | Data Binding Dim strSQL As String SELECT FROM Products Then we open a new SQLConnection using the connection string. Dim sqlConn As New strConnection The myCommand data command is created by passing it the statement and connection strings. We can then use myCommand to cause the DataReader to execute the SQL statement that we want - in this case to select all records from the Products table. Dim myCommand As New strSQL sqlConn Dim myReader As However as we learned previously the DataReader retrieves the records one at a time in a forward-only and read-only format. The last part of code retrieves each record in the DataReader one at a time and writes the Product Id and Product Name to the Output window using the method Do While Product Id 0 _ vbTab Product Name 1 Loop Notice the use of the GetInt32 and GetString methods of the DataReader object. These methods can be used because we know the data types of the underlying data fields. By explicitly using the typed accessor methods in this way we reduce the amount of type conversion that is required when retrieving the data. Last of all we have the line that closes the DataReader. It is very important to note that a DataReader is open until you close the connection with such a line of code or the object gets destroyed and thus the connection is closed at some point during garbage collection . You can modify this simple example for your own purposes but this should give you an idea of how to a DataReader can be used to rapidly retrieve forward-only read-only data. The most important idea to take away from this section is that you should use a DataReader whenever possible and especially when an in-memory copy of data is not required. 45 Chapter 8 Summary In this chapter we ve .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.