c# - How to get the value of the checkListBox -


i working on windows form application , have checklistbox binded database. using parameter method store selected text. however, want primary key of item similar combobox.selectedvalue instead of text. there way this?

here code. can see, parameter filtered checkeditem text. when select checkeditem checklistbox, suppose selected items. work fine if checklistbox item has peter, amy, bob, , david (non duplicate name). however, if checklistbox has duplicate name. peter, amy, amy, bob, david, amy,this cause problem. if select first amy, parameterlist have amy, amy, amy. problem because filtering firstname (so whenever see same name, add parameterlist. want filter key such employeeid not have duplicate name in parameterlist. (just when change combobox.selecteindex combobox.selectedvalue). when selected the first amy, parameterlist should have 1 checked amy, not amy isn't checked. wondering if can selectedvalue combobox value` map database value? appreciated

for example here checklistbox:

[x]amy []peter []david []amy []amy []jimmy 

you can see first amy selected. parameterlist has amy, amy, amy since filtering firstname.

    string parameterlist = "";     int parametercounter = 0;      // add parameter placeholder each "checked" item     (var t = 0; t < employeechecklistbox.checkeditems.count; t++)     {         parameterlist += (t == 0) ? "@p" + t : ", @p" + t;      }      string query = "select distinct firstname, lastname, employeeemail,                             entryyear, leaveyear                      from[employee_detail] ed                      left join[department_detail] dd on ed.employeeid = dd.employeeid                     firstname = (" + parameterlist + ")";      mycommand = new sqlcommand(query, myconn);      (var t = 0; t < employeechecklistbox.checkeditems.count; t++)     {         mycommand.parameters.addwithvalue ("@p" + t, employeechecklistbox.checkeditems[t].tostring());     }           if (employeechecklistbox.checkeditems.count == 0)     {             mycommand = new sqlcommand(equery, myconn);     } 

here want change

string query = "select distinct firstname, lastname, employeeemail,                                 entryyear, leaveyear                          from[employee_detail] ed                          left join[department_detail] dd on ed.employeeid = dd.employeeid                         firstname = (" + parameterlist + ")"; 

//the parameterlist should selected value of checklistbox

your problem have multiple employees same name, , how user differentiate between them on ui.

so easy , quick fix problem is, change content on ui displaying in checkboxlist.

since each employee have unique email id... display emailid along name.. change query below..

select td.teacherid id, chinesename + ' ' + email name from[teacher_detail] ..... 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -