Đang chuẩn bị liên kết để tải về tài liệu:
Using XPath to Query Data in a DataSet

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

[ Team LiB ] Recipe 8.6 Using XPath to Query Data in a DataSet Problem You need to use an XPath expression to extract certain rows from a DataSet. Solution Use SelectSingleNode( ) or SelectNodes( ). The sample code contains two event handlers: Form. | Team LiB Recipe 8.6 Using XPath to Query Data in a DataSet Problem You need to use an XPath expression to extract certain rows from a DataSet. Solution Use SelectSingleNode or SelectNodes . The sample code contains two event handlers Form.Load Sets up the sample by creating a DataSet containing the Orders table and Order Details table from Northwind and a nested relation between the two tables. Go Button.Click Executes an XPath query to retrieve the Orders and Order Details data for an OrderlD specified by the user to an XmlNode. The results are displayed by iterating over the XmlNode to retrieve the Orders and the XmlNodeList containing the Order Details. The C code is shown in Example 8-9. Example 8-9. File XPathQueryForm.cs Namespaces variables and constants using System using System.Configuration using System.Windows.Forms using System.Text using System.Xml using System.Data using System.Data.SqlClient Table name constants private const String ORDERS_TABLE Orders private const String ORDERDETAILS_TABLE OrderDetails Relation name constants private const String ORDERS_ORDERDETAILS_RELATION Orders_OrderDetails_Relation Field name constants private const String ORDERID_FIELD OrderlD private DataSet ds . . . private void XPathQueryForm_Load object sender System.EventArgs e ds new DataSet Orders_OrderDetails SqlDataAdapter da Fill the Order table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Orders ConfigurationSettings.AppSettings S ql_ConnectString DataTable orderTable new DataTable ORDERS_TABLE da.Fill orderTable ds.Tables.Add orderTable Fill the OrderDetails table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Order Details ConfigurationSettings.AppSettings S ql_ConnectString DataTable orderDetailTable new DataTable ORDERDETAILS_TABLE da.Fill orderDetailTable ds.Tables.Add orderDetailTable Create a relation between the tables. ds.Relations.Add ORDERS_ORDERDETAILS_RELATION ds.Tables ORDERS_TABLE .Columns ORDERID_FIELD ds.Tables .