title: Add full row to DataTable MVC4
body: <p>i'm new to MVC and I am trying to build a DataTable from a stored procedure response and pass it back to my View. For the rows I build a comma delimited string full of cell values. </p>
  
  <p>The issue I am having is that the string is not getting parsed by the commas, and effectively it is passing the whole string into the first cell of each row.</p>
  
  <p>What is the correct way to build up a row comprised of the individual values for each column? The number of columns, their names, and amount of records returned are all variable.</p>
  
  <pre><code>    public ActionResult dataSet(string table, string key, string search)
      {
          SqlDataReader rdr = null;
          SqlConnection con = new SqlConnection("Connection stuff");
          SqlCommand cmd = new SqlCommand();
          cmd = new SqlCommand("dbo.USP_getDataSet", con);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@key", key);
          cmd.Parameters.AddWithValue("@table", table);
          cmd.Parameters.AddWithValue("@search", search);
          con.Open();
  
          DataTable theTable = new DataTable();
          try
          {
              rdr = cmd.ExecuteReader();
              while (rdr.Read())
              {
                  int count = rdr.FieldCount;
                  string rowString = "";
                  int intRows = theTable.Columns.Count;
                  //Build columns on first pass through
                  if (intRows == 0){
                      for (int i = 0; i &lt; count; i++){
                          theTable.Columns.Add(Convert.ToString(rdr.GetName(i).TrimEnd()), typeof(string));                    
                      }
                  }
  
                  //Grab all values for each column
                  for (int i = 0; i &lt; count; i++){                        
                      rowString += '\"' + (Convert.ToString(rdr.GetValue(i)).TrimEnd()) + '\"' + ", ";                        
                  }
  
                  //Remove trailing delimiter
                  string finishedRow = rowString.Substring(0, rowString.Length - 2);
  
                  //Add the full row for each time through reader
                  theTable.Rows.Add(finishedRow);
             } 
          }
  
          finally
          {
              if (rdr != null)
              { rdr.Close(); }
              if (con != null)
              { con.Close(); }
          }
          return View(theTable);
      }
  </code></pre>