TAILIEUCHUNG - The DataSet Class phần 3

The output from this program is as follows: numberOfRows = 3 Reading from the Products DataTable ProductID = 1 ProductName = Chai UnitPrice = 18 ProductID | The output from this program is as follows numberOfRows 3 Reading from the Products DataTable ProductID 1 ProductName Chai UnitPrice 18 ProductID 2 ProductName Chang UnitPrice 19 Reading from the Customers DataTable CustomerlD ALFKI CompanyName Alfreds Futterkiste Changing the CommandText Property of the SelectCommand You can also populate a DataSet with multiple DataTable objects by changing the CommandText property of the SelectCommand for your DataAdapter object before each call to the Fill method. First the following code populates a DataSet with a DataTable containing two rows from the Products table SqlCommand mySqlCommand SELECT TOP 2 ProductID ProductName UnitPrice FROM Products ORDER BY ProductID SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlCommand DataSet myDataSet new DataSet int numberOfRows myDataSet Products The myDataSet object now contains a DataTable named Products. Next the CommandText property for the SelectCommand of mySqlDataAdapter is changed to a SELECT statement that retrieves rows from the Customers table and the Fill method is called again SELECT CustomerID CompanyName FROM Customers WHERE CustomerlD ALFKI numberOfRows myDataSet Customers The myDataSet object now contains an additional DataTable named Customers. Listing shows a program that uses the code examples shown in this section. illustrates how to populate a DataSet object with multiple DataTable objects by changing the CommandText property of a DataAdapter object s SelectCommand using System using using class MultipleDataTables2 public static void Main SqlConnection mySqlConnection new SqlConnection server localhost database .

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.