Performing a SQL SELECT Statement and Storing the Rows Locally phần 2

The Fill() method then creates a DataTable in the DataSet with the specified name and runs the SELECT statement. The DataTable created in your DataSet is then populated with the rows retrieved by the SELECT statement. | The Fill method then creates a DataTable in the DataSet with the specified name and runs the SELECT statement. The DataTable created in your DataSet is then populated with the rows retrieved by the SELECT statement. The following example calls the Fill method of mySqlDataAdapter passing myDataSet and Customers to the Fill method myDataSet Customers The Fill method creates a DataTable object named Customers in myDataSet and populates it with the rows retrieved by the SELECT statement. You can access these rows even when disconnected from the database. Step 11 Close the Database Connection Close the database connection using the Close method of the SqlConnection object created in the first step. For example Note Of course you don t have to immediately close the database connection before reading locally stored rows from your DataSet. I close the connection at this point in the example to show that you can indeed read the locally stored rows- even when disconnected from the database. Step 12 Get the DataTable Object From the DataSet Object Get the DataTable object created in step 10 from the DataSet object. You get a DataTable from your DataSet using the Tables property which returns a DataTableCollection object. To get an individual DataTable from your DataSet you pass the name of your DataTable in brackets Customers for example to the Tables property. The Tables property will then return your requested DataTable which you can store in a new DataTable object that you declare. In the following example Customers returns the Customers DataTable created in myDataSet in step 10 and stores the returned DataTable in myDataTable DataTable myDataTable Customers Note You can also specify the DataTable you want to get by passing a numeric value to the Tables property. For example 0 also returns the Customers DataTable. Step 13 Display the Columns for Each Row in the DataTable Display

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
9    80    2    16-05-2024
128    79    2    16-05-2024
Đã 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.