The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Strange DataBinding behaviour

Last post 09-03-2008, 4:15 PM by David.Parsons. 2 replies.
Sort Posts: Previous Next
  •  08-28-2008, 12:29 AM 10990

    Strange DataBinding behaviour

    Dear sir, I'm evaluating ES2008 and found a strange behaviour with databinding.

    Suppose I have 2 tables

    Order: OrderID, OrderDate

    OrderDetail: OrderID, Product

    Order.OrderID <->> OrderDetail.OrderID relationship

    OrderID is not an AutoNumber/Identity so I must supply it in code.

    Code1: This works perfectly 

     

    Code:
    dim o as new Order()
    o.OrderID = 1
    o.OrderDate = #01/01/2008#
    
    dim od as OrderDetail()
    od = o.OrderDetailCollectionByOrderID.AddNew()
    od.Product = "XYZ"
    
    o.Save()


    Code2: This code does not work 

     

    Code:
    dim o_coll as new OrderCollection
    dim o as Order()
    dim od as OrderDetail()
    dim bs as new bindingsource
    
    bs.datasource=o_coll
    o = bs.AddNew()
    o.OrderID = 1
    o.OrderDate = #01/01/2008#
    bs.ResetBindings(false)
    od = ctype(bs.current, OrderDetail).OrderDetailCollectionByOrderID.AddNew()
    od.Product = "XYZ"
    
    o_coll.Save()
    
     

    In Code2, the field value of od.OrderID is nothing so I receive error when trying to save. I don't know why it is not automatically filled with o.OrderID value. Do I missing something here?

    Regards,

    Lewi 

  •  08-28-2008, 5:21 AM 11001 in reply to 10990

    Re: Strange DataBinding behaviour

    I think you might have to call EndEdit or something, let me refer David to this thread, he knows more about this issue.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-03-2008, 4:15 PM 11152 in reply to 10990

    Re: Strange DataBinding behaviour

    Call AddNew() on the collection. With option strict and explicit on, this line will not compile for me, since bs.Current is an Order, not a OrderDetail.

    Code:
    od = ctype(bs.current, OrderDetail).OrderDetailCollectionByOrderID.AddNew()

    If you are doing everything in code, you do not need to use a BindingSource.

    Code:
    dim o_coll as new OrderCollection
    
    dim o as new Order()
    o = o_coll.AddNew()
    o.OrderID = 1
    o.OrderDate = #01/01/2008#
    
    dim od as OrderDetail()
    od = o.OrderDetailCollectionByOrderID.AddNew()
    od.Product = "XYZ"
    
    o_coll.Save()

    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML