c# - is never assigned to, and will always have its default value -


im trying select name dropdown list created database. cant seem mane assign.

when click select button not carry persons name in combobox1 through me next lot of code.

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.data.oledb; using system.data.sql;  namespace glidinglogsgui2 { public partial class instructorselectionform : form {     list<person> instructors = new list<person>();     person selectedperson;      public instructorselectionform()     {         initializecomponent();         this.topmost = true;          list<person> instructors = new list<person>();         oledbcommand com = new oledbcommand("select * personnel [current?] = true , [position] = ?", program.db_connection);         com.parameters.add(new oledbparameter("", positionids.instructor));          oledbdatareader dr = com.executereader();          while (dr.read())         {             try             {                 instructors.add(new person(dr));             }             catch             {             }         }          foreach (person in instructors)         combobox1.items.add(a.firstname + " " + a.surname);     }      private void selectbutton_click_1(object sender, eventargs e)     {         if (selectedperson == null)         {             messagebox.show("a person must selected first");             return;         }          new f5363(selectedperson);     }      private void cancelbutton_click_1(object sender, eventargs e)     {         this.close();      }      private void instructorselectform_load(object sender, eventargs e)     {      }       } } 

you're declaring selectedperson, never setting anywhere. suspect want remove current declaration of selectedperson , change click event similar to;

private void selectbutton_click_1(object sender, eventargs e) {       person selectedperson = combobox1.selecteditem person;     if (selectedperson == null)     { ... 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -