c# - How to get and assign entire column form Database to individual button's text? -


i trying values of entire column in table , assign them individual button text.

this have achieved far.

            string query = "select type service";             mysqlcommand command = new mysqlcommand(query, con);             var reader = command.executereader();             if (reader.read())             {                 button5.text = reader[0].tostring();                 button6.text = reader[1].tostring();                 button7.text = reader[2].tostring();                 button8.text = reader[3].tostring();                 button9.text = reader[4].tostring();                 button10.text = reader[5].tostring();                 button11.text = reader[6].tostring();                 button14.text = reader[7].tostring();                 button15.text = reader[8].tostring();                 button16.text = reader[9].tostring();                 button17.text = reader[10].tostring();                 button18.text = reader[11].tostring();             } con.close(); 

i can assign 1 value button5, how values?

change if(reader.read()) while(reader.read()).

if checks if rows present, while iterates through reader.

you can create array of buttons:

button[] btnarray = {button5, button6,... , on} 

then use while condition:

int i=0; while(reader.read()) {     string name = reader.getstring(0);     btnarray[i].text = name;     ++i;     if(i == btnarray.length) break; //jus in case there more values in reader in array. } 

and don't forget close reader. reader.close()


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -