title: Multiple stored procedure calls or loop through an array?
body: <p>I am currently setting the tooltips on a report grid based on values stored in a table. I do this because I have a LOT of grids and a lot of tooltips and this makes it easy to manage them all from one place without updating source code.</p>
  
  <p>My question. Is it faster to load the tooltips in this fashion or to load them by loading all of tooltips at once and looping through an array?</p>
  
  <p>It seems that one SP call for all of the tooltips would be faster than 10-20. Is this assumption correct? If so, can I see an example of how you'd do this in an array or list?</p>
  
  <pre><code>            sqlconn.Open();
          SqlCommand com = new SqlCommand("sp_ToolTipLookup", sqlconn) { CommandType = System.Data.CommandType.StoredProcedure };
          SqlParameter pFieldName = new SqlParameter("@FieldName", "");
          for (int i = 0; i &lt; rptgrid.Columns.Count; i++) 
          {
              pFieldName.Value = rptgrid.Columns[i].ToString();
              com.Parameters.Add(pFieldName); //adding the field name to the SP
              SqlDataReader data = com.ExecuteReader(); //Open the SP
              if (data.Read()) rptgrid.Columns[i].ToolTip = data["ToolTip"].ToString(); //If there is a resulting Tooltip, apply it to the grid
              data.Close();
              com.Parameters.Remove(pFieldName);
          }
          sqlconn.Close();
  </code></pre>
  
  <p>An example using a list would be more like this (and if this is faster, I could potentially load the list once per session and just store it in memory).</p>
  
  <pre><code>sqlconn.Open();
          SqlCommand com = new SqlCommand("Select * from ToolTips", sqlconn) { CommandType = System.Data.CommandType.Text };
          SqlDataReader data = com.ExecuteReader();
          List&lt;ToolTip&gt; tips = new List&lt;ToolTip&gt;();
          while (data.Read())
          {
              tips.Add(new ToolTip { fieldname = data["FieldName"].ToString(), tooltip = data["ToolTip"].ToString() } );
          }
  
  
  
          for (int i = 0; i &lt; rptgrid.Columns.Count; i++) //Changed to visible column to speed it up a bit.
          {
              for (int x = 0; x &lt; tips.Count; x++)
              {
                  if (rptgrid.Columns[i].Name == tips[x].fieldname)
                  {
                      rptgrid.Columns[i].ToolTip = tips[x].tooltip;
                  }
              }
          }
          data.Close();
          sqlconn.Close();
  </code></pre>