Browse multiple related tables in ADO.NET data set (4)

xiaoxiao2021-03-06  38

In ADO.NET dataset browse multiple related tables (4) Author: Microsoft www.ASPCool.com Time: 2003-1-23 17:38:22

Display Related Records Now you already have related records of the selected customer (stored in the data line array), you can display them in order to interact with the user. The application will access the data in the data line array returned by the getChildrow method one by one, and add the "order ID" of each related record as a separate item to the list box. Note: Although this sample one by one to access the data in the relevant data row of the array, a list box may have been used but the properties window, the DataSource property, the DataMember ValueMember attributes and properties are bound to the relevant records. Display related records in the list box In the Solution Explorer (Solution Explorer), right-click Form1 and select View Code from the shortcut menu. In the SELECTEDEXCHANGED event handler of the combo box created in the front step, add the following code to the code in the handler: 'Visual Basic' When the selected customer is changed, the order list is cleared. LBORDERS.ITEMS.CLEAR () RTBDETAILS.TEXT = "" 'Adds the order ID of each related order to the list box. DRORDER AS DATAROW for Each DrORDER IN DRAORDERS LBORDERS.ITEMS.ADD (DRORDER ("ORDERID")) Next // C # // Clear a list of order when changing the selected customer. LBORDERS.ITEMS.CLEAR (); rtBDetails.text = ""; // Adds the order ID of each related order to the list box. Foreach (DataRow DrORDER IN DRAORDERS) {lborders.Items.Add (DRORDER ["ORDERID"]);} Save the project. Run the application. The list of orders will be displayed in the list box. Select another customer in the combo box and the order list will be updated. Close the form. Browse related records in three or more tables browsing three or more tables as simple as handling two tables. To learn how to handle more than two tables, add the ordering schedule and product table to the DSNorthWind data set. After selecting an order in the list box, the details of the order are displayed in the RTF text box. In order to meet the constraint rules, you need to delete an existing data relationship and recreate it again. Temporarily delete DataRelation in the DSNorthWind data set In the Solution Explorer (Solution Explorer), double-click DSNorthWind.xsd to open it in the XML Designer (XML Designer). Select an existing CustomersRDERS relationship and remove it. Save the project. Now you need to add additional two tables to existing data sets and create a new DataRelation object to connect all tables together. Add the Order Ming Table and Product Table to the DSNorthWind Dataset in the Solution Explorer (Solution Explorer), right-click Form1 and select View Designer from the shortcut menu. Drag the "Order Detail" table from the Server Explorer (Server Explorer) to the form. A new data adapter will appear in the component bar.

转载请注明原文地址:https://www.9cbs.com/read-72612.html

New Post(0)