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

xiaoxiao2021-03-06  43

In ADO.NET dataset browse multiple related tables (6) Author: Microsoft www.ASPCool.com Time: 2003-1-23 17:40:06 Views: 9727

Expression columns include Datacolumn allocation values ​​based on the results of the expression in addition to the static data. The expression is a string assigned to the Datacolumn.expression property. When the expression is used with the related data, the data column can include the calculation of the relevant data column. The total information of the relevant data columns. The logic comparison result of related data. To illustrate the value expression column when processing related data, we will introduce one example for each usage and add it to the DataRelelationExample application. Add the column calculated by the expression column containing the calculated value contains the mathematical operation results. It can be calculated from the existing columns. A new column named Total will be added in the order list, which will contain the value returned by the expression UNITprice * Quantity (the total dollar value of the order). Add an expression list in the Solution Explorer (Solution Explorer), right-click Form1 and select View Code from the shortcut menu. Add the following code to the existing code above the Form1_Load event handler: 'Visual Basic' Creates an expression column named Total in the Order Illumination Table. Dim dcTotal as DataColumn = new DataColumn ( "Total") dcTotal.DataType = System.Type.GetType ( "System.Decimal") dcTotal.Expression = "UnitPrice * Quantity" DsNorthwind1.Order_Details.Columns.Add (dcTotal) // C # // Create an expression column called Total in the ordering schedule. DataColumn dcTotal = new DataColumn ( "Total"); dcTotal.DataType = System.Type.GetType ( "System.Decimal"); dcTotal.Expression = "UnitPrice * Quantity"; dsNorthwind1.Order_Details.Columns.Add (dcTotal); Run application. Select a order in the list box, check the order in the RTF text box, and note that each record has a new TOTAL column, display the product of the Unitprice and Quantity fields. Close the form. Adding an expression column EXPRESSION attribute containing a total information supports several total functions (SUM, AVG, COUNT, etc.). For more information, see the Datacolumn.Expression property. To demonstrate how to generate a total information, you need to add a new column named Ordertotal in the order table. This column will use the SUM function, returns the total dollar value of all sub orders detail based on the order selected in the list box (LBorders). This value is then displayed above each order in the RTF text box. Creating an OrdertOTAl list in the Solution Explorer (Solution Explorer), right-click Form1 and select View Code from the shortcut menu.

In the Form1_Load event handler, add the following code to the following code to create a Total column below: 'Visual Basic' Create an expression column named Ordertotal in the order table. Dim dcOrderTotal as DataColumn = new DataColumn ( "OrderTotal") dcOrderTotal.DataType = System.Type.GetType ( "System.Decimal") dcOrderTotal.Expression = "Sum (Child.Total)" DsNorthwind1.Orders.Columns.Add (dcOrderTotal) // C # // Create a list of expression columns named ORDERTOT in the order table. DataColumn dcTotal2 = new DataColumn ( "OrderTotal"); dcTotal2.DataType = System.Type.GetType ( "System.Decimal"); dcTotal2.Expression = "Sum (Child.Total)"; dsNorthwind1.Orders.Columns.Add (dcTotal2 ); Display the total information to all orders in all orders in the LBORDERS_SELECTEDINDEXCHANGED event handler, add the following code to Dim Details as string = "" or String Details = "" Row: 'Visual Basic Details = Order Total: "& String.format (" {0: C} ", _ dsnorthwind1.orders.FindbyOrderid (CTYPE (LBORDERS.SELECTEDITEM, _ Integer) (" OrdeerTotal ") & controlchars.crf // C # Details =" Order Total: " String.format (" {0: C} ", dsnorthwind1.orders.FindbyOrderId ((int) lborders.selectedItem) [" Ordertotal "]) " / n "; run the application. Select a order in the list box, note that the total amount of all orders in the selected order will appear in the first line in the RTF text box. Select another order in the list box and display the update to reflect the newly selected order. Close the form. Adding an expression column Expression attribute that contains logical evaluations can populate a certain data column based on the calculated value in other columns. For example, the OrderSize column in the order table can contain value "BIG" (if the total amount is greater than 1000) or "small" (if the total amount is less than 1000). To demonstrate this type of expression, you need to add code to the DataRelelationExample application to do the following: Add data columns named ORDERSIZE in the order table. Fill the ORDERSIZE column based on the value of the relevant order detail. At the top of the RTF text box, the value of the ORDERSIZE column and the value of the OrdertAl are simultaneously displayed.

Add Creating the Create ORDERSIZE column In the Solution Explorer (Solution Explorer), right-click Form1 and select View Code from the shortcut menu. In the Form1_Load event handler, add the following code to the following code to create the code of the OrdertTotal column in the order table: 'Visual Basic' Creates an expression column named ORDERSIZE in the order table. Dim dcOrderSize as DataColumn = new DataColumn ( "OrderSize") dcOrderSize.DataType = System.Type.GetType ( "System.String") dcOrderSize.Expression = "IIF (Sum (Child.Total) <1000, 'Small', 'Big ') "DSNorthWind1.orders.columns.add (dcordersize) // c # // Create an expression column named ORDERSIZE in the order table. DataColumn dcOrderSize = new DataColumn ( "OrderSize"); dcOrderSize.DataType = System.Type.GetType ( "System.String"); dcOrderSize.Expression = "IIF (Sum (Child.Total) <1000, 'Small', 'Big ') "; Dsnorthwind1.orders.columns.add (dcordersize); Display ORDERSIZE value In the lborders_selectedIndexchanged event handler, add the following code to the top of the first for Each:' Visual Basic Details & =" ("& CType (DsNorthwind1.Orders.FindByOrderID _ (CType (lbOrders.SelectedItem, Integer)) ( "OrderSize"), String) & ")" _ & ControlChars.CrLf // C # details = "(" dsNorthwind1.Orders.FindByOrderID (INT) LBORDERS.SELECTEDITEM ["ORDERSIZE"] ") / n"; run the application. Select a order in the list box. Check the first line in the RTF text box. Ordersize selected will be displayed on the right side of Ordertotal. Select another order in the list box and display the update to reflect the newly selected order. From the Debug menu, select STOP DEBUGGING (stop debugging). Additional information about related tables It is necessary to mention some other information to enrich the content of this article. The order in which the relevant data sheet is filling the relevant data sheet is very important to the filling order of the data sheet, which has a great impact on the output of the data, so it must be considered when designing the application. For example, please pay attention to the last filled client table. When filling the customer table, the combo box will populate the customer name value.

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

New Post(0)