how to get combobox selected value in integer
-
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
-
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
-
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 ;)
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
-
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
-
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?
-
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
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
-
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
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 wellTextBox1.Text = "EmployeeName" TextBox1.Tag = "EmployeeID"
Have a Nice day ahead!!! Regards,ZAK