c# - Read and display selected rows in datatable -


i have created datatable displays data gathered datareader. problem not display rows being selected. displays 1 row.how can display rows being selected?

code behind

        int quantity;         string jobname;         string ordertype;         datetime duedate;          sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["connect"].connectionstring);          string cmdtext = "select quantity,job_name,[order],due_date shopping_cart uid=@uidd";          sqlcommand cmd = new sqlcommand(cmdtext, con);          //===== adding parameters/values.         cmd.parameters.addwithvalue("@uidd", hfuserid.value);          //===== check current state of connection object. if closed open connection         //===== execute insert query.         if (con.state == connectionstate.closed)         {             con.open();         }          //===== execute query.         sqldatareader dr = cmd.executereader();         dr.read();          quantity = dr.getint32(0);         jobname = dr.getstring(1);         ordertype = dr.getstring(2);         duedate = dr.getdatetime(3);          con.close();         if (session["uid"] != null)         {             datatable dt = new datatable();             dt.columns.addrange(new datacolumn[4] {                             new datacolumn("quantity", typeof(string)),                             new datacolumn("job name", typeof(string)),                             new datacolumn("order type", typeof(string)),                              new datacolumn("due date", typeof(string))});              dt.rows.add(quantity, jobname, ordertype, duedate);    yourtable.append("<table border = '1'>");             yourtable.append("<tr>");             foreach (datacolumn column in dt.columns)             {                 yourtable.append("<th style = 'background-color: #0bd2d1;color:#ffffff'>");                 yourtable.append(column.columnname);                 yourtable.append("</th>");             }             yourtable.append("</tr>");             foreach (datarow row in dt.rows)             {                 yourtable.append("<tr>");                 foreach (datacolumn column in dt.columns)                 {                     yourtable.append("<td>");                     yourtable.append(row[column]);                     yourtable.append("</td>");                 }                 yourtable.append("</tr>");             } 

rather

dr.read() 

use

while(dr.read()) {     // stuff } 

that way loop on rows in datareader.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -