Pls help with expression columns

sboyko

New member
Joined
Sep 1, 2005
Messages
2
Programming Experience
Beginner
I have 3 datatables (Customers, Orders, OrderPositions), 2 relations (Customer_Orders, Order_OrderPositions), 3 bindingsources (bsCustomers, bsOrdersByCustomer, bsOrderPositionsByOrderByCustomer) and 1 datagrid(view) bound to bsOrderPositionsByOrderByCustomer.

I need to know total orders amount for each customer, so i add expression columns (one for calculating order position total, another - for order total, and one more for all client's orders total).

When trying to edit a cell in my datagridview (for example, change ordered qty) I receive a StackOverflowException - why?

The only reason is EXPRESSION COLUMNS (((.

Could you pls help me to solve the problem? Any reply would be appreciated.


--------------------------------------------
Pls add this code on any empty form Form_Load procedure and try edit values in datagridview...
----------------------------------------------

Imports System.data
Public Class Form1
Public ds As New DataSet
Public Customers As New DataTable("Customers")
Public Orders As New DataTable("Orders")
Public OrderPositions As New DataTable("OrderPositions")
Public dgvCustomers As New DataGridView

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds.Tables.Add(Customers)
ds.Tables.Add(Orders)
ds.Tables.Add(OrderPositions)
Customers.Columns.Add("CustomerID", Type.GetType("System.Int32"))
Orders.Columns.Add("CustomerID", Type.GetType("System.Int32"))
Orders.Columns.Add("OrderID", Type.GetType("System.Int32"))
OrderPositions.Columns.Add("OrderID", Type.GetType("System.Int32"))
OrderPositions.Columns.Add("OrderPositionID", Type.GetType("System.Int32"))
OrderPositions.Columns.Add("OrderPositionProductID", Type.GetType("System.Int32"))
OrderPositions.Columns.Add("OrderPositionQuantity", Type.GetType("System.Int32"))
OrderPositions.Columns.Add("OrderPositionPrice", Type.GetType("System.Double"))
Dim Customer_Orders As New DataRelation("Customer_Orders", Customers.Columns(0), Orders.Columns(0), False)
Dim Order_OrderPositions As New DataRelation("Order_OrderPositions", Orders.Columns(1), OrderPositions.Columns(0), False)
ds.Relations.Add(Customer_Orders)
ds.Relations.Add(Order_OrderPositions)
OrderPositions.Columns.Add("OrderPositionTotal", Type.GetType("System.Double"), "OrderPositionQuantity*OrderPositionPrice")
Customers.Rows.Add(New Object() {1})
Customers.Rows.Add(New Object() {2})
Orders.Rows.Add(New Object() {1, 1})
Orders.Rows.Add(New Object() {2, 2})
OrderPositions.Rows.Add(New Object() {1, 1, 1, 1, 1.01})
OrderPositions.Rows.Add(New Object() {2, 2, 2, 2, 2.02})

Orders.Columns.Add("OrderTotal", Type.GetType("System.Double"), "Sum(Child(Order_OrderPositions).OrderPositionTotal)")
Customers.Columns.Add("CustomerOrdersTotal", Type.GetType("System.Double"), "Sum(Child(Customer_Orders).OrderTotal)")
Dim bsCustomers As New BindingSource
bsCustomers.DataSource = Customers
Dim bsOrdersByCustomer As New BindingSource
bsOrdersByCustomer.DataSource = bsCustomers
bsOrdersByCustomer.DataMember = "Customer_Orders"
Dim bsOrderPositionsByOrderByCustomer As New BindingSource
bsOrderPositionsByOrderByCustomer.DataSource = bsOrdersByCustomer
bsOrderPositionsByOrderByCustomer.DataMember = "Order_OrderPositions"
With dgvCustomers
.Parent = Me
.Dock = DockStyle.Fill
.DataSource = bsOrderPositionsByOrderByCustomer
End With
End Sub
End Class

-------------

P.S. In another applicatrion i received StackOverflowException when trying update my datatable to MSSQL server (the datatable also had expression columns) - maybe you know why, too?
 
I am not getting any errors with this code...
 
Back
Top