c# - Anyone have method easier than this? -


i have code , in reader. how can reader.read without if methods?

        system.windows.forms.textbox txt = new system.windows.forms.textbox();          oledbcommand command = new oledbcommand();         command.connection = connection;         string query = " select * other order type";         command.commandtext = query;         oledbdatareader reader = command.executereader();           txt.text = "txtpertanyaan"+cleft;         this.controls.add(txt);         txt.top = cleft *25;         txt.left = 100;          if (cleft == 1)         {             if (reader.hasrows)             {                  reader.read();                  txt.text = reader["type"].tostring();                 reader.read();              }         }         else if (cleft ==2)         {             if (reader.hasrows)             {                  reader.read();                 reader.read();                 txt.text = reader["type"].tostring();                 reader.read();              }         }         else if (cleft == 3)         {             if (reader.hasrows)             {                  reader.read();                 reader.read();                 reader.read();                 txt.text = reader["type"].tostring();                 reader.read();              }         }          cleft = cleft+1;         return txt;      } 

thanks advice. use dynamic textbox add automatically if click button.

i want if cleft=1 reader.read()=1, duuno if cleft=10? must must write if condition until 10 times? long ...

if looking rid of if statements use for instead.

system.windows.forms.textbox txt = new system.windows.forms.textbox();  oledbcommand command = new oledbcommand(); command.connection = connection; string query = " select * other order type"; command.commandtext = query; oledbdatareader reader = command.executereader();  txt.text = "txtpertanyaan"+cleft; this.controls.add(txt); txt.top = cleft *25; txt.left = 100;  if (reader.hasrows) {     (int = 0; < cleft ; i++)     {         reader.read();     }     txt.text = reader["type"].tostring();     reader.read(); }      cleft = cleft+1; return txt; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -