Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Filling a combo box from a database

Filling a combo box from a database

Scheduled Pinned Locked Moved C#
questiondatabasexmlperformancehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jefferys
    wrote on last edited by
    #1

    I am wanting to know what is the best way to fill a combo box from data in a database. Right now I am using an data adapter to fill a dataset that is set as the datasource for the combo box. This seams to work ok. From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? On another combo box I have in my program I use a dataset to read an xml file. Then I use a foreach loop to add the data to the combobox. It is a small list of 10 or so records. The only problem with this is that I haven't found a way to add a value to each item in the combo box. Using the dataset I can set the display member and value member. Just wanted to know what everyone though about this. I am also concerned about how much memory is taken up by the comboboxes and the datasets that fill them. Please let me know what you think about this. I know it is a small thing I want to make sure I'm using the best method. Thanks, JefferyS :)

    D 1 Reply Last reply
    0
    • J Jefferys

      I am wanting to know what is the best way to fill a combo box from data in a database. Right now I am using an data adapter to fill a dataset that is set as the datasource for the combo box. This seams to work ok. From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? On another combo box I have in my program I use a dataset to read an xml file. Then I use a foreach loop to add the data to the combobox. It is a small list of 10 or so records. The only problem with this is that I haven't found a way to add a value to each item in the combo box. Using the dataset I can set the display member and value member. Just wanted to know what everyone though about this. I am also concerned about how much memory is taken up by the comboboxes and the datasets that fill them. Please let me know what you think about this. I know it is a small thing I want to make sure I'm using the best method. Thanks, JefferyS :)

      D Offline
      D Offline
      DougW48
      wrote on last edited by
      #2

      I almost always use a dataset for the for the combo box. I would imagine that most others here would agree that there is nothing wrong with using datasets for combo boxes. Jefferys wrote: From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? If you are using the Fill method of a dataAdapter to fill your dataset, then you are usually in a disconnected state. The Adapter connects to the database for the query, and then disconnects when it is finished. If you are using a dbConnection object, and opening/closing the connection yourself, then it's possible that you might be leaving the connection open. Either way, it is safer to let the dataAdapter do the work for you.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups