title: Procedure or function has too many arguments specified
body: <p>I am trying to get the value of the CategoryID so that I can insert that value into the database when an admin wants to update product features. The stored procedure that was written is for a ListView, so I was hoping I could put something hidden in there to get the ID. When I put the Hidden Field on the page and tried to get the ID, I got the error I mentioned in the title.</p>
  
  <pre><code> &lt;ul id="categories"&gt;
          &lt;asp:ListView ID="lvAncestorCategories" runat="server" DataSourceID="dsCategoryAncestors"&gt;
              &lt;ItemTemplate&gt;
              &lt;li&gt;&lt;%# Eval("CategoryName") %&gt;&lt;/li&gt;
              &lt;li&gt;
                  &lt;asp:HiddenField ID="CategoryID" runat="server" Value='&lt;%# Eval("CategoryID") %&gt;' /&gt;
              &lt;/li&gt;
              &lt;/ItemTemplate&gt;
              &lt;ItemSeparatorTemplate&gt; &gt; &lt;/ItemSeparatorTemplate&gt;
          &lt;/asp:ListView&gt;
      &lt;/ul&gt;
  
  
  &lt;asp:SqlDataSource ID="dsCategoryAncestors" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ProductsConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:ProductsConnectionString.ProviderName %&gt;" 
      SelectCommand="getCategoryAncestorsByProductID" 
      SelectCommandType="StoredProcedure"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter Name="ProductID" QueryStringField="id" 
              Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
      &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter Name="CategoryID" QueryStringField="id" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>I did not write the stored procedure so I have no idea what it is doing, I got an error saying that my listview didn't have a value for @CategoryID so I added it to the stored procedure in the SELECT statement. Not knowing how the stored procedure works, I got the "too many arguments" error.</p>
  
  <pre><code>Dim featureSql As String = "INSERT INTO Marketing(ProductID, 
  MarketingTypeID, MarketingTitle, MarketingData) 
  VALUES ( @ProductID, 3, 'Feature', @MarketingData);
  UPDATE Product SET ModifyDate = getdate(), 
  ModifyUser = @ModifyUser 
  WHERE ProductID = @ProductID; 
  INSERT INTO Feature (FeatureTitle, CategoryID) 
  VALUES (@FeatureTitle, @CategoryID)"
  
              Using cn As New SqlConnection
              (System.Configuration.ConfigurationManager.ConnectionStrings
              ("LocalSqlServer").ConnectionString)
  
                  Using cmd As New SqlCommand(featureSql, cn)
  
                      cmd.Parameters.Add(New SqlParameter("@FeatureTitle", txtFeature.Text))
                      cmd.Parameters.Add(New SqlParameter("@CategoryID", CategoryID.Value))
                  End Using
              End Using
  &lt;asp:SqlDataSource ID="dsCategoryAncestors" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ProductsConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:ProductsConnectionString.ProviderName %&gt;" 
      SelectCommand="getCategoryAncestorsByProductID" 
      SelectCommandType="StoredProcedure"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter Name="ProductID" QueryStringField="id" 
              Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
      &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter Name="CategoryID" QueryStringField="id" Type="Int32"  /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Stored Procedure:</p>
  
  <pre><code>USE [Products]
  GO
  /****** Object:  StoredProcedure [dbo].[getCategoryAncestorsByProductID]    
  Script Date: 11/11/2011 13:28:29 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  
  ALTER PROCEDURE [dbo].[getCategoryAncestorsByProductID]
  -- Add the parameters for the stored procedure here
  @ProductID int
  AS
  BEGIN
  -- This stored procedure gets all the lineage of a particular category
  
  -- Create a temp table to hold the lineage in order
  CREATE TABLE #FamilyTree (
      OrderNumber int,
      CategoryID int,
      CategoryName nvarchar(max)
  )
  
  DECLARE @CategoryID nvarchar(max)
  SET @CategoryID = 
     (SELECT CategoryID 
      FROM CategoryLink 
      WHERE ProductID = @ProductID)
  
  DECLARE @CategoryName nvarchar(max)
  SELECT @CategoryName = CategoryName FROM Category WHERE CategoryID = @CategoryID
  
  -- Insert child category into table first giving it an OrderNumber of 1 
      -- the higher the number, the higher in the tree
  INSERT INTO #FamilyTree VALUES (1,@CategoryID,@CategoryName)
  
  -- Use this for the OrderNumber. Increment by 1 for each level.
  DECLARE @OrderNumber int
  SET     @OrderNumber = 2
  
  -- Use this to hold the new CategoryID to add to the familytree table
  DECLARE @AncestorID INT
  
  WHILE (SELECT COUNT(*) FROM Category 
             WHERE CategoryID = 
            (SELECT ParentID FROM Category 
             WHERE CategoryID = @CategoryID)) &gt; 0
  BEGIN
  
      SELECT @AncestorID = CategoryID, @CategoryName = CategoryName 
              FROM Category WHERE CategoryID = 
              (SELECT ParentID FROM Category 
              WHERE CategoryID = @CategoryID)
  
      INSERT INTO #FamilyTree VALUES (@OrderNumber,@AncestorID,@CategoryName)
      SET @OrderNumber = @OrderNumber + 1
      SET @CategoryID = @AncestorID --Moves to the next CategoryID to see if it
                                              has any parents
  
  END
  
  --Returns Categories in order from Parents to Children
  SELECT CategoryName FROM #FamilyTree ORDER BY OrderNumber DESC
  
  DROP TABLE #FamilyTree
  
  END
  </code></pre>
  
  <p>This is what I want to work:</p>
  
  <pre><code>Dim featureSql As String = "INSERT INTO Marketing
                              (ProductID, MarketingTypeID, MarketingTitle, MarketingData) 
                              VALUES ( @ProductID, 3, 'Feature', @MarketingData);
                              UPDATE Product 
                              SET ModifyDate = getdate(), ModifyUser = @ModifyUser 
                              WHERE ProductID = @ProductID; 
                              INSERT INTO Feature (FeatureTitle, CategoryID) 
                              VALUES (@FeatureTitle, @CategoryID)"
              Using cn As New SqlConnection
              (System.Configuration.ConfigurationManager.ConnectionStrings
              ("LocalSqlServer").ConnectionString)
  
                  Using cmd As New SqlCommand(featureSql, cn)
  
                      cmd.Parameters.Add(New SqlParameter("@FeatureTitle", txtFeature.Text))
                      cmd.Parameters.Add(New SqlParameter("@CategoryID", CategoryID.Value))
                  End Using
              End Using
  </code></pre>