开发者

passing comboBox name to procedure

开发者 https://www.devze.com 2023-02-16 20:39 出处:网络
dear all I have many comb boxes in many forms of my application, andecah should be filled with items from th开发者_开发百科e database

dear all I have many comb boxes in many forms of my application, and ecah should be filled with items from th开发者_开发百科e database so, I want to make store procedure with a combo box name passed as paremeter and then call it from any form

I don't know how to pass it, as what type ? please help


It sounds as though your approach to this problem isn't optimal.

The notion of a "combo-box" isn't usually something which you want to entangle with your database constructs.

Design your application with the intent of modeling you domain's "concepts" in one application layer as classes. If some of this data is frequently needed, and rarely changed, you may want to implement caching of some of this data. Subsequently you can design your UI and associate comboboxes with required lists and collections exposed by your domain model.

Edit: If you really want to use some inherent aspect of the combobox as a parameter into the database (for obtaining items), then I guess you could consider using the Tag property of the control for this. This strategy allows you to have multiple comboboxes on the same form with the same options (such as multiple Yes/No or Opened/Closed combos) without having to deal with naming/uniqueness conflicts.

  • Create a method e.g. GetComboSourceData() which takes a System.Windows.Forms.ControlCollection as parameter.
  • Inside this method, iterate the controls, looking for Comboboxes. If they have the Tag property set, then send this tag as a parameter to your database query. Assign the returned dataset as datasource to the individual combos.
  • When loading your forms make sure to call GetComboSourceData(this.Controls) to populate your combos.
0

精彩评论

暂无评论...
验证码 换一张
取 消