user3198588 user3198588 - 7 months ago 84
SQL Question

How to add data for sql to combobox?

this code is working

TextBoxService is a combobox

Dim sql As String
DTS = New DataSet
sql = "SELECT * FROM Service"
dap = New SqlDataAdapter(sql, CON)
dap.Fill(DTS, "Service")
TextBoxService.DataSource = DTS.Tables("Service")
TextBoxService.DisplayMember = "ServiceName"
TextBoxService.ValueMember = "ServiceID"

because I need to at it to 2 comboboxes. it will change both comboboxes when I selectd a combobox.
so i try to use this

bds = New BindingSource
DTS = New DataSet
bds.DataSource = DTS.Tables("Service")
TextBoxService.DataSource = bds
TextBoxService.DisplayMember = "ServiceName"
TextBoxService.ValueMember = "ServiceID"

but it show this error
Cannot bind to the new display member


There is more than one way to this the easy and simple I find is if you

*import the SQL data base in data sources *Select the table you want and set the object type eg( combobox, textbox or checkbox) *Then select eg combobox and click on the small arrow to the top left hand corner *Select you data source(table), display member(field name) * then go to the properties of the combobox object and select data binding plus sign * click on text and click the data source (table) and field you want to display the data from