Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting multiple rows into html table ASP.Net
    text
    copied!<p>I have a query that selects rows according to a certain defined criteria. Once that happens I have a reader that gets the values for use. My problem is how can I get a variable amount of rows the reader returned to my ASP.Net behind code page? Also be able to get the individual rows and not just the first row. I am not sure if a counter needs to be set or honestly what to do. How can I get these variable amounts of rows into the appropriate labels? If you want to see any code let me know.</p> <p>DBHelper class where:</p> <pre><code>private DBHelper() { } public static SqlConnection getConnection() { return new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString); } public static SqlConnection getFRESHConnection() { return new SqlConnection(ConfigurationManager.ConnectionStrings["FRESHConnection"].ConnectionString); } public static SqlDataReader executeQuery(SqlConnection dbConn, string sqlString, SqlParameter[] parameters) { SqlCommand cmd = null; SqlDataReader reader = null; try { if (dbConn.State == ConnectionState.Closed) dbConn.Open(); cmd = dbConn.CreateCommand(); cmd.CommandText = sqlString; if (parameters != null) { cmd.Parameters.AddRange(parameters); } reader = cmd.ExecuteReader(); cmd.Dispose(); } catch (Exception ex) { throw ex; } return reader; } </code></pre> <p>DataClass:</p> <pre><code>public class LineAData { public int CaseNum6; public int CaseNum9; public int Group; public bool Completed; public int WorkID; public void load(int Group1, int Group2) { StringBuilder sqlString = new StringBuilder(); sqlString.Append("SELECT WorkID, CaseNum6, CaseNum9, Group, Completed "); sqlString.Append("FROM WorkOrder "); sqlString.Append("WHERE Group = @Group1 OR Group = @Group2 "); sqlString.Append("AND Completed = '0' "); SqlDataReader reader = null; SqlConnection dbConn = DBHelper.getConnection(); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Group1", Group1 ), new SqlParameter("@Group2", Group2) }; try { reader = DBHelper.executeQuery(dbConn, sqlString.ToString(), parameters); if (reader != null) { if (reader.Read()) { WorkID = (int)(reader["WorkID"]); CaseNum6 = (int)(reader["CaseNum6"]); CaseNum9 = (int)(reader["CaseNum9"]); Group = (int)(reader["Group"]); Completed = (bool)reader["Completed"]; } else throw new Exception("No record returned"); reader.Close(); reader.Dispose(); dbConn.Close(); dbConn.Dispose(); } } catch (Exception ex) { throw ex; } finally { if (dbConn != null) { try { dbConn.Close(); dbConn.Dispose(); } catch { } } if (reader != null) { try { reader.Close(); reader.Dispose(); } catch { } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload