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. Visual Basic
  4. how to get combobox selected value in integer

how to get combobox selected value in integer

Scheduled Pinned Locked Moved Visual Basic
databasetutorialquestion
7 Posts 4 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.
  • K Offline
    K Offline
    Kissy16
    wrote on last edited by
    #1

    I am filling combo box as per below code,and i want to insert the respectibe selected item's code from the database into other table. how to get selected value? My code for filling combo box is.. dbconn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:\guest\dmb.mdb") dbconn.Open() sql = "Select distinct DESIGNATION from DESIG" dbcomm = New OleDb.OleDbCommand(sql, dbconn) dbread = dbcomm.Executereader() cmbdesig.Items.Clear() While dbread.Read cmbdesig.Items.Add(dbread("DESIGNATION")) End While dbread.close() dbconn.Close() Designation table have both desig_code and designation. I want to get the selected value (desig_code).Which property should i set to get it?? Answer please

    kissy

    B T 2 Replies Last reply
    0
    • K Kissy16

      I am filling combo box as per below code,and i want to insert the respectibe selected item's code from the database into other table. how to get selected value? My code for filling combo box is.. dbconn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:\guest\dmb.mdb") dbconn.Open() sql = "Select distinct DESIGNATION from DESIG" dbcomm = New OleDb.OleDbCommand(sql, dbconn) dbread = dbcomm.Executereader() cmbdesig.Items.Clear() While dbread.Read cmbdesig.Items.Add(dbread("DESIGNATION")) End While dbread.close() dbconn.Close() Designation table have both desig_code and designation. I want to get the selected value (desig_code).Which property should i set to get it?? Answer please

      kissy

      B Offline
      B Offline
      brjames32
      wrote on last edited by
      #2

      Hi Kissy Something like:

      daGroups.Fill(ds, "Groups")
      cboTeachingGrp.DataSource = ds.Tables("Groups")
      cboTeachingGrp.DisplayMember = "groupcode"

      Where Groups is the column containing the info from the database. Hope this helps ;)

      K 1 Reply Last reply
      0
      • B brjames32

        Hi Kissy Something like:

        daGroups.Fill(ds, "Groups")
        cboTeachingGrp.DataSource = ds.Tables("Groups")
        cboTeachingGrp.DisplayMember = "groupcode"

        Where Groups is the column containing the info from the database. Hope this helps ;)

        K Offline
        K Offline
        Kissy16
        wrote on last edited by
        #3

        Thanks for ur answer. But ur code is not working. Here i want it like in asp.net dropdownlist's Datatextfield(TEXT) and datavaluefield(code). So when iwant to insert code ,i can use only the selectedvalue. but in ur code it,is displaying code in the combobox. i want to display text and insert the respective code. Give me some other suggestion in frawework 2.0. Windows application using vb in framework 2.0

        kissy

        B 1 Reply Last reply
        0
        • K Kissy16

          Thanks for ur answer. But ur code is not working. Here i want it like in asp.net dropdownlist's Datatextfield(TEXT) and datavaluefield(code). So when iwant to insert code ,i can use only the selectedvalue. but in ur code it,is displaying code in the combobox. i want to display text and insert the respective code. Give me some other suggestion in frawework 2.0. Windows application using vb in framework 2.0

          kissy

          B Offline
          B Offline
          brjames32
          wrote on last edited by
          #4

          Kissy Sorry I assumed you were using OleDb to connect to your Database. Can you paste what you have so far so we can see?

          K 1 Reply Last reply
          0
          • B brjames32

            Kissy Sorry I assumed you were using OleDb to connect to your Database. Can you paste what you have so far so we can see?

            K Offline
            K Offline
            Kissy16
            wrote on last edited by
            #5

            Please check my first post,i have already pasted my code there.

            kissy

            1 Reply Last reply
            0
            • K Kissy16

              I am filling combo box as per below code,and i want to insert the respectibe selected item's code from the database into other table. how to get selected value? My code for filling combo box is.. dbconn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:\guest\dmb.mdb") dbconn.Open() sql = "Select distinct DESIGNATION from DESIG" dbcomm = New OleDb.OleDbCommand(sql, dbconn) dbread = dbcomm.Executereader() cmbdesig.Items.Clear() While dbread.Read cmbdesig.Items.Add(dbread("DESIGNATION")) End While dbread.close() dbconn.Close() Designation table have both desig_code and designation. I want to get the selected value (desig_code).Which property should i set to get it?? Answer please

              kissy

              T Offline
              T Offline
              Tom Deketelaere
              wrote on last edited by
              #6

              you want the property's combobox.displaymember combobox.valuemember but you'r sql string only contains 1 column ??? simplest way to do what you want is to get a datatable from you'r connection and bind it to the combobox and then set the 2 property's

              Dim dt As New DataTable
              dim DbConnection as New OleDbConnection([ConnectionString])
              dbconnection.open()
              Dim da As New OleDbDataAdapter(Sql, DbConnection)
              da.Fill(dt)

              combobox.datasource = dt
              combobox.displaymember = "column to show"
              combobox.valuemember = "column that contains unique key"

              hope this helps

              Z 1 Reply Last reply
              0
              • T Tom Deketelaere

                you want the property's combobox.displaymember combobox.valuemember but you'r sql string only contains 1 column ??? simplest way to do what you want is to get a datatable from you'r connection and bind it to the combobox and then set the 2 property's

                Dim dt As New DataTable
                dim DbConnection as New OleDbConnection([ConnectionString])
                dbconnection.open()
                Dim da As New OleDbDataAdapter(Sql, DbConnection)
                da.Fill(dt)

                combobox.datasource = dt
                combobox.displaymember = "column to show"
                combobox.valuemember = "column that contains unique key"

                hope this helps

                Z Offline
                Z Offline
                zahedonline
                wrote on last edited by
                #7

                Yes as mentioned above use combobox.valuemember for capturing the Primary Key Column which is commonly used for Edit and Deleting mode!!! Example:- ********** combobox.datasource = dt combobox.displaymember = "EmployeeName" combobox.valuemember = "EmployeeID" Hope this helps you in understanding the diffrence between Displaymember and valuemember similar example in TextBox control as well TextBox1.Text = "EmployeeName" TextBox1.Tag = "EmployeeID" Have a Nice day ahead!!! Regards,

                ZAK

                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