locked
entity framework - set empty datasource RRS feed

  • Question

  • Hello !

    i'm using entity framework , and i have a form with bindingsource , and some bound textboxes ( all bound at design time)

    Depending to some option that user select , i need to display all the records , or some of the records  , or no records.

    i have a button select , and on Click event i have :

    if contitions1 then

    Mybindingsource.datasource=From t in context.table1 where .......  some conditions                                            

                                                   select t

    else

    Mybindingsource.datasource=context.table1

    end if

    Everything is ok when the instruction in else section is executed , or when the From.... Where..... select result non empty.

    When From....where.... select  is empty i get an error :

    Cannot bind to the property or column xxxxxxx on the DataSource.
    Parameter name: dataMember

    what can i do ?

    Because i need that the textboxes controls on form becomes empty if no records on selection.

    thank you.

    Saturday, November 26, 2011 4:38 PM

Answers

  • it's strange , but if i change :

    Mybindingsource.datasource=From t in context.table1 where .......  some conditions                                            

                                                   select t

    to :

    Mybindingsource.datasource=(From t in context.table1 where .......  some conditions                                            

                                                   select t).Tolist

     

    everything is ok when From.... where... select is empty or non empty.

    • Proposed as answer by Tyler_A Sunday, November 27, 2011 6:30 PM
    • Marked as answer by Alan_chen Monday, November 28, 2011 7:36 AM
    Saturday, November 26, 2011 8:59 PM

All replies

  •  Sometimes binding is a crutch that leads a programmer to not know how to
    load controls manually. In some cases, it's much easier to load controls
    manually instead of trying to bind everything and not have needed
    functionality.
     
    Saturday, November 26, 2011 7:38 PM
  • it's strange , but if i change :

    Mybindingsource.datasource=From t in context.table1 where .......  some conditions                                            

                                                   select t

    to :

    Mybindingsource.datasource=(From t in context.table1 where .......  some conditions                                            

                                                   select t).Tolist

     

    everything is ok when From.... where... select is empty or non empty.

    • Proposed as answer by Tyler_A Sunday, November 27, 2011 6:30 PM
    • Marked as answer by Alan_chen Monday, November 28, 2011 7:36 AM
    Saturday, November 26, 2011 8:59 PM