mysql - vb.net display database record to a different combobox from a single database table with different records -


vb.net display database record different combobox single database table different records

i have 2 comboboxes , want show different records in each combobox, , i'm using 1 table in database, code shows error, hmm

my table schema:

| cid | cpos........| cfname | cmname | clname | cyr | cparty | | 1..| president. | john....| ark....|..smith.| 3 ..| glory..|

private sub form4_load(byval sender system.object, byval e system.eventargs) handles mybase.load     con.connectionstring = ("server=localhost;user id=root;database=db")     try         con.open()          cmd             .connection = con             .commandtext = "select concat_ws(' ', cfname, cmname, clname,'from', cparty cpos like='president') fullname candidate;"         end         dim dt new datatable          combobox1             da.selectcommand = cmd             da.fill(dt)             .datasource = dt             .displaymember = "fullname"             .valuemember = "fullname"         end           cmd             .connection = con             .commandtext = "select concat_ws(' ', cfname, cmname, clname,'from', cparty cpos like='vice president') fullname candidate;"         end         combobox2             da.selectcommand = cmd             da.fill(dt)             .datasource = dt             .displaymember = "fullname"             .valuemember = "fullname"         end       catch ex exception         msgbox(ex.message)     end try     con.close() end sub 

looking @ previous question, think commandtext should this

.connection = con .commandtext = "select concat_ws(' ', cfname, cmname, clname, cparty) fullname " & _                "from candidate cpos like='vice president'" 

this join info 4 columns cfname, cmname, clname , cparty in single column named fullname, condition on field cpos extract 'vice president' or 'president' roles.

also suggest change order of properties setting on combobox

 .displaymember = "fullname"  .valuemember = "fullname"  .datasource = dt 

you avoid execute 2 queries retrieve same info database in way

 cmd     .connection = con      ' if have president , vice president in candidate table      ' remove clause      .commandtext = "select concat_ws(' ', cfname, cmname, clname, cparty) fullname, " & _                    "cpos, cid candidate cpos like='vice president' or " & _                    "cpos 'president'"  end 

then separate data using dataview datasource of combobox

da.selectcommand = cmd da.fill(dt) combobox1    dim dv = new dataview(dt, "cpos 'president'", "", dataviewrowstate.currentrows)    .displaymember = "fullname"    .valuemember = "fullname"    .datasource = dv end with combobox2    dim dv1 = new dataview(dt, "cpos 'vice president'", "", dataviewrowstate.currentrows)    .displaymember = "fullname"    .valuemember = "fullname"    .datasource = dv1 end 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -