Đang chuẩn bị liên kết để tải về tài liệu:
The DataSet Class phần 3

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

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 mySqlConnection.CreateCommand mySqlCommand.CommandText SELECT TOP 2 ProductID ProductName UnitPrice FROM Products ORDER BY ProductID SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlDataAdapter.SelectCommand mySqlCommand DataSet myDataSet new DataSet mySqlConnection.Open int numberOfRows mySqlDataAdapter.Fill 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 mySqlDataAdapter.SelectCommand.CommandText SELECT CustomerID CompanyName FROM Customers WHERE CustomerlD ALFKI numberOfRows mySqlDataAdapter.Fill myDataSet Customers mySqlConnection.Close The myDataSet object now contains an additional DataTable named Customers. Listing 10.6 shows a program that uses the code examples shown in this section. Listing_10.6 _MULTIPLEDATATABLES2.CS_ MutlipleDataTables2.cs 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 System.Data using System.Data.SqlClient class MultipleDataTables2 public static void Main SqlConnection mySqlConnection new SqlConnection server localhost database .

Đã 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.