vb.net - How to populate a ComboBox based on another ComboBox through SQL Server? -


i want able have 2 comboboxes 1 parent or owner of second one, through connection string on sql server. means whenever select value in first combobox, second combobox filter it's results display corresponding values related first combobox. if see code below, error states:

error 1 method 'private sub cboclient_selectedindexchanged(sender object, e system.eventargs, envname string)' cannot handle event 'public event selectedindexchanged(sender object, e system.eventargs)' because not have compatible signature.

goal:

  1. change database connection
  2. query proper user data correct database
  3. populate user combo box user data

my code:

 private sub cboclient_selectedindexchanged(sender object, e eventargs, byval envname string) handles cboclient.selectedindexchanged         using con2 new sqlconnection(configurationmanager.connectionstrings("constr").connectionstring)             'getting connection string specific client             dim cmd2 new sqlcommand("select * tblconnections envname = '" & "@envname" & "'", con2)             con2.open()             dim dt new datatable             dt.load(cmd2.executereader())             cmd2.parameters.add("@envname", sqldbtype.varchar)             cmd2.parameters("@envname").value = envname             if dt.rows.count > 0                 dim clientconstring string = dt(0)("connectionstring")                 'getting yalusers info client specific database\                 using con3 new sqlconnection(clientconstring)                     cmd2 = new sqlcommand("select * yalusers", con3)                     con3.open()                     dt.load(cmd2.executereader())                     cbouser.datasource = dt                     cbouser.displaymember = "first_name"                     cbouser.valuemember = "id"                     con3.close()                 end using              else                 'show error message : missing connection string in yalconnections table               end if              con2.close()         end using     end sub 

how can fixed?

update: when run app, have 6 items in first combobox , ever 1 select, doesn't populate second combobox. why??

you cannot add parameter event handler. must have definition:

private sub cboclient_selectedindexchanged(sender object, e eventargs) handles cboclient.selectedindexchanged     doselectedindexchanged(sender, e, something) end sub 

create separate subroutine work need not let handle event.

private sub doselectedindexchanged(sender object, e eventargs, byval envname string) handles cboclient.selectedindexchanged 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -