c# - How To Get All Data[Row] from Ms Database in Dynamic TextBox -


i have code this

int cleft=0; public system.windows.forms.textbox addnewtextbox() {     system.windows.forms.textbox txt = new system.windows.forms.textbox();     oledbcommand command = new oledbcommand();     command.connection = connection;     string query = " select * dotmatrix;     command.commandtext = query;     oledbdatareader reader = command.executereader();     this.controls.add(txt);     txt.top = (cleft*25) + 124;     txt.left = 50;     txt.height = 20;     txt.width = 259;     while (reader.read())     {         txt.text=reader["pertanyaan"].tostring();     }     if (txt.text=="")     {         messagebox.show("pertanyaan  habis , akan redirect ke hasil");     }     cleft = cleft + 1;     return txt; }  private void textbox1_textchanged_1(object sender, eventargs e) {    addnewtextbox(); } 

my question is, why textbox show 1 line database??? want show data[row] in pertanyaan row answer

this line looping through every row , overwriting textbox value:

while (reader.read()) {     txt.text=reader["pertanyaan"].tostring(); } 

so same textbox being assigned on , over.

your textbox creation code wants moved inside loop, this:

while (reader.read()) {     system.windows.forms.textbox txt = new system.windows.forms.textbox();     txt.top = (cleft*25) + 124;     txt.left = 50;     txt.height = 20;     txt.width = 259;     txt.text=reader["pertanyaan"].tostring();     if (txt.text=="")     {         messagebox.show("pertanyaan  habis , akan redirect ke hasil");     }     this.controls.add(txt); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -