title: Execute stored procedure and using returned information in cshtml
body: <p>My previous question on this subject was poorly asked, so I want to start by asking a more concise question that is really the core of my issue.  In my .cs Model, I have to call a stored procedure that brings up the number of tasks for each  project.  </p>
  
  <p>The specific thing I need is the number of tasks that each project may have, which is returned as the sp parameter UnfinishedTaskCount.  </p>
  
  <p>The razor in my cshtml file will display the returned information, which was another issue I managed to figure out, but getting the info I want is the final hurdle.  Here is the code in the .cs file where I need to have the correct call to the stored procedure:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Data;
  using System.Data.SqlClient;
  
  namespace IntelliBase.Models
  {
      public partial class Project:Description
      {
         ....
  
          private int unfinishedtasks;
          public int UnFinishedTaskCount
          {
              get
              {
                  SqlConnection sqlConnection1 = new SqlConnection("Data Source=ORLANDOSQL1;Integrated Security=True");
                  SqlCommand cmd = new SqlCommand();
                  Object returnValue;
  
                  cmd.CommandText = "mp_Display_Projects_Home";
                  cmd.Parameters.Add("@BeginPage", SqlDbType.VarChar).Value = 0;
                  cmd.Parameters.Add("@EndPage", SqlDbType.VarChar).Value = 0;
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = sqlConnection1;
  
                  sqlConnection1.Open();
                  returnValue = cmd.ExecuteScalar();
                  sqlConnection1.Close();
  
                  return unfinishedtasks = (int)returnValue;
              }
              set { ; }
          }
  
      }
  }
  </code></pre>
  
  <p>The ExecuteScalar command will only bring back the first row information, which doesn't help since there are more rows of projects each with their own set of tasks, and I read that ExecuteNonQuery will not return specific parameters, just all the data; I don't need all the data, just the UnfinishedTaskCount for each project.  </p>
  
  <p>So because of the ExecuteScalar, it returns "2" for the number of tasks for all the projects in the table because the project in the first row has two tasks (the other projects have different numbers of tasks).  Is there another Execute-- call that will grab the correct number of tasks for each project so I can display them correctly on the cshtml?  I appreciate everyone's patience; this is my first big C# project and I'm kind of anxious to get this working correctly.</p>