title: Exception "Procedure or function expects parameter, which was not supplied." thrown even after supplying the parameter
body: <p>I am trying insert some entries in the database using a stored procedure which is called by a C# method as shown below:</p>
  
  <pre><code>public int addProfile(UserProfile NewUserPro)
  {
      DataSet ds = ExecuteStoredProcedure("AddNewPro", new SqlParameter[]{
                  new SqlParameter("@UserID", NewUserPro.UsrId),
                  new SqlParameter("@Type", NewUserPro.Type),
                  new SqlParameter("@Phone", NewUserPro.Phone),
                  new SqlParameter("@Name", NewUserPro.Name),
                  new SqlParameter("@FatherName", NewUserPro.FatherName),
                  new SqlParameter("@GroupID", NewUserPro.GroupID),
                  new SqlParameter("@IsPublic", 0)});
              return int.Parse(ds.Tables[0].Rows[0][0].ToString());
  }
  </code></pre>
  
  <p><code>ExecuteStoredProcedure()</code> is a C# method created by me. It executes specified stored procedure and returns the output as a <code>DataSet</code>. This is the definition of that function:</p>
  
  <pre><code>public DataSet ExecuteStoredProcedure(string ProcedureName, SqlParameter[] Parameters)
  {
      try
      {
           using (SqlCommand com = new SqlCommand("[dbo]." + ProcedureName))
           {
                com.CommandType = CommandType.StoredProcedure;
                foreach (SqlParameter sp in Parameters)
                     com.Parameters.Add(sp);
                return SelectDataSet(com);
           }
      }
      catch (Exception e)
      {
          throw e;
      }
  }   
  </code></pre>
  
  <p>As you can see in <code>addProfile()</code> method I am already providing <code>@IsPublic</code> parameter, but it's still throwing following exception:</p>
  
  <blockquote>
    <p>Procedure or function 'AddNewPro' expects parameter '@IsPublic',
    which was not supplied.</p>
  </blockquote>
  
  <p><code>@IsPublic</code> parameter is an <code>int</code> parameter that saves value to <code>[IsPublic]</code> field which is an <code>int</code> field in a table with <code>null</code> allowed.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I am including the input parameters of the stored procedure. I think that will be enough? If you want I can include complete stored procedure but it's a lengthy code and due to some confidentiality reasons I have to cut some lines.</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[AddNewPro]
      @UserID int,
      @Name NVARCHAR(MAX),
      @Type int,
      @Phone VARCHAR(MAX),
      @GroupID int,
      @FatherName VARCHAR(MAX),
      @IsPublic int
  AS
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Ok I found a little hint to the solution. When I put the breakpoint on the first line of <code>ExecuteStoredProcedure</code>, I found that its getting the value of <code>@IsPublic</code> as null. But I provided the value while adding the parameters. Why this is happening? </p>