Đang chuẩn bị liên kết để tải về tài liệu:
Finding Rows in a DataTable

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

[ Team LiB ] Recipe 3.8 Finding Rows in a DataTable Problem You need to find a row or group of rows in a DataTable meeting certain criteria. Solution Choose from the three techniques shown in the sample code to locate data in the table meeting user-specified criteria. | Team LiB Recipe 3.8 Finding Rows in a DataTable Problem You need to find a row or group of rows in a DataTable meeting certain criteria. Solution Choose from the three techniques shown in the sample code to locate data in the table meeting user-specified criteria. The sample code contains two event handlers Form.Load Sets up the sample by creating a DataTable containing the Orders table from the Northwind sample database. The default view of the table is bound to the data grid on the form. Find Button.Click Uses three different techniques the DataTable.Select method the DataTable.Rows.Find method and the DataView.RowFilter property to find rows in the Orders table matching the user-specified Country. The C code is shown in Example 3-8. Example 3-8. File FindDataTableRowsForm.cs Namespaces variables and constants using System using System.Configuration using System.Data using System.Data.SqlClient Table name constants private const String ORDERS_TABLE Orders Field name constants private const String ORDERID_FIELD OrderlD private const String SHIPCOUNTRY_FIELD ShipCountry . . . private void FindDataTableRowsForm_Load object sender System.EventArgs e Fill the Orders table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders ConfigurationSettings.AppSettings S ql_ConnectString DataTable dt new DataTable ORDERS_TABLE da.Fill dt da.FillSchema dt SchemaType.Source Bind the table to the grid. dataGrid.DataSource dt.DefaultView private void findButton_Click object sender System.EventArgs e Get the table bound to the grid. DataTable dt DataView dataGrid.DataSource .Table Build the filter using contents of the text box. String filter SHIPCOUNTRY_FIELD shipCountryTextBox.Text . Locate the records using the Select method of the DataTable. DataRow drc dt.Select filter resultTextBox.Text DataTable.Select returned drc.Length record s . Environment.NewLine Iterate over the collection of rows filtered in the previous step and find them in the table using the Find method of the

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.