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. Populate combobox

Populate combobox

Scheduled Pinned Locked Moved C#
databasehelp
17 Posts 5 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.
  • S Shivaprasad D Atthigode

    :)what a mess is this!! "cbo.extension.text" will never populate items in to combobox control, this only displays the specified text if it is already there in combobox items collection. to populate the items u should specifie { combobox.items.add(dtr["filterKey"].tostring()); }

    M Offline
    M Offline
    matjame
    wrote on last edited by
    #7

    cboExtension.items.add(dtr["filterKey"].tostring()); items gives this error "System.Web.UI.WebControl.DropdownList doesnt contain definition for items." Then to .tostring() "object doesnt contain a definition for string Can you generate a code that would work. NB. The Items in the database are jus A.B.C til Z So, it suppose to load A B C Till Z Thank you for your help.A nice code would be nice.Im an amature in this

    kagiso

    S S 2 Replies Last reply
    0
    • J J4amieC

      sujithkumarsl wrote:

      status = ExecuteNonQuery_SP("Select * from Filter");//getting the value cmbStatus.DataSource =status ;

      :confused::|

      --- How to get answers to your questions[^]

      S Offline
      S Offline
      sujithkumarsl
      wrote on last edited by
      #8

      status = ExecuteNonQuery_SP("Select * from Filter");//getting the value cmbStatus.DataSource =status ; actually ExecuteNonQuery_SP("Select * from Filter"); is a method which takes quaery as parameter and returns the datatable. i used this code in my proj and its working

      My small attempt...

      J 1 Reply Last reply
      0
      • M matjame

        cboExtension.items.add(dtr["filterKey"].tostring()); items gives this error "System.Web.UI.WebControl.DropdownList doesnt contain definition for items." Then to .tostring() "object doesnt contain a definition for string Can you generate a code that would work. NB. The Items in the database are jus A.B.C til Z So, it suppose to load A B C Till Z Thank you for your help.A nice code would be nice.Im an amature in this

        kagiso

        S Offline
        S Offline
        sujithkumarsl
        wrote on last edited by
        #9

        please try the exable which i gave to you. that will work which field from db, you want to add in combobox?

        My small attempt...

        M 1 Reply Last reply
        0
        • M matjame

          cboExtension.items.add(dtr["filterKey"].tostring()); items gives this error "System.Web.UI.WebControl.DropdownList doesnt contain definition for items." Then to .tostring() "object doesnt contain a definition for string Can you generate a code that would work. NB. The Items in the database are jus A.B.C til Z So, it suppose to load A B C Till Z Thank you for your help.A nice code would be nice.Im an amature in this

          kagiso

          S Offline
          S Offline
          Shivaprasad D Atthigode
          wrote on last edited by
          #10

          using sytem.oledb; using system.windows.forms; oledbconnection connect=new oledbconnection; oledbcommand command=new oledbbcommand("Select 'field_name' from 'tabel' where 'condition'", connect); oledbreader reader=command.executeReader(); reader.read(); { combobox1.items.add(reader[0].tostring()); } reader.close(); connect.close();

          M 2 Replies Last reply
          0
          • S sujithkumarsl

            please try the exable which i gave to you. that will work which field from db, you want to add in combobox?

            My small attempt...

            M Offline
            M Offline
            matjame
            wrote on last edited by
            #11

            I want to filter by FilterKey

            kagiso

            1 Reply Last reply
            0
            • S Shivaprasad D Atthigode

              using sytem.oledb; using system.windows.forms; oledbconnection connect=new oledbconnection; oledbcommand command=new oledbbcommand("Select 'field_name' from 'tabel' where 'condition'", connect); oledbreader reader=command.executeReader(); reader.read(); { combobox1.items.add(reader[0].tostring()); } reader.close(); connect.close();

              M Offline
              M Offline
              matjame
              wrote on last edited by
              #12

              using sytem.oledb; using system.windows.forms; oledbconnection connect=new oledbconnection; oledbcommand command=new oledbbcommand("Select 'field_name' from 'tabel' ***There are only two fields. ID & FilterKey and Im using FilterKey so no need for where ***** where 'condition'", connect); oledbreader reader=command.executeReader(); reader.read(); { combobox1.items.add(reader[0].tostring()); } reader.close(); connect.close();

              kagiso

              1 Reply Last reply
              0
              • J J4amieC

                sujithkumarsl wrote:

                status = ExecuteNonQuery_SP("Select * from Filter");//getting the value cmbStatus.DataSource =status ;

                :confused::|

                --- How to get answers to your questions[^]

                M Offline
                M Offline
                matjame
                wrote on last edited by
                #13

                Im using MS Access not SQL

                kagiso

                1 Reply Last reply
                0
                • S Shivaprasad D Atthigode

                  using sytem.oledb; using system.windows.forms; oledbconnection connect=new oledbconnection; oledbcommand command=new oledbbcommand("Select 'field_name' from 'tabel' where 'condition'", connect); oledbreader reader=command.executeReader(); reader.read(); { combobox1.items.add(reader[0].tostring()); } reader.close(); connect.close();

                  M Offline
                  M Offline
                  matjame
                  wrote on last edited by
                  #14

                  Ok, its not taking the using system.Windows.forms; and the combobox1.items.add(reader[0].tostring()); says its doesnot have a definition for Add. Everything else was what I did before

                  kagiso

                  S 1 Reply Last reply
                  0
                  • S sujithkumarsl

                    status = ExecuteNonQuery_SP("Select * from Filter");//getting the value cmbStatus.DataSource =status ; actually ExecuteNonQuery_SP("Select * from Filter"); is a method which takes quaery as parameter and returns the datatable. i used this code in my proj and its working

                    My small attempt...

                    J Offline
                    J Offline
                    J4amieC
                    wrote on last edited by
                    #15

                    sujithkumarsl wrote:

                    actually ExecuteNonQuery_SP("Select * from Filter"); is a method which takes quaery as parameter and returns the datatable. i used this code in my proj and its working

                    Two things: 1) There is no method named ExecuteNonQuery_SP in the framework, and therefore using it in an example to a newer programmer is just going to confuse them more! This method is most likely defined in your own project, or is part of a data access framework that you use. 2) The name of the method would imply that it executes IDbConnection.ExecuteNonQuery which does not "return a table". If your method really does take a SQL clause as a parameter and return a table it should be named ExecuteDataTable_SP Please take the time to consider the usefulness of the code and the target audience before posting a (useless) code snippet.

                    --- How to get answers to your questions[^]

                    1 Reply Last reply
                    0
                    • M matjame

                      Ok, its not taking the using system.Windows.forms; and the combobox1.items.add(reader[0].tostring()); says its doesnot have a definition for Add. Everything else was what I did before

                      kagiso

                      S Offline
                      S Offline
                      Shivaprasad D Atthigode
                      wrote on last edited by
                      #16

                      hi if its a web application, it wont take windows.forms, and u wont get combobox control also.... in such case, use " using system.web.ui.webcontrols; " { dropdownlist1.items.add(reader[0].tostring()); } this will defenetely work:)

                      M 1 Reply Last reply
                      0
                      • S Shivaprasad D Atthigode

                        hi if its a web application, it wont take windows.forms, and u wont get combobox control also.... in such case, use " using system.web.ui.webcontrols; " { dropdownlist1.items.add(reader[0].tostring()); } this will defenetely work:)

                        M Offline
                        M Offline
                        matjame
                        wrote on last edited by
                        #17

                        This should do it.I will keep you posted, jus have to configure my database

                        kagiso

                        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