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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
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.