将SqlDataSource与存储过程一起使用时,过程或函数指定的参数太多

时间:2017-07-10 06:13:28

标签: asp.net sql-server stored-procedures sqldatasource

我想使用SqlDataSource更新两个表。我使用的控件是Gridview。我有一个存储过程。但是我收到了错误:

  

过程或函数指定了太多参数

我知道我的问题已经重复,但我已经尝试了许多解决方案,但我的问题仍未解决。 以下是我的SqlDataSource代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IHDConnectionString %>" 
            SelectCommand="SELECT issue.issue_id, issue.pro_id, project.name, issue.type, issue.summary, issue.mem_id, issue.priority, issue.status, issue.impact, CONVERT (date, GETDATE()) AS Expr1, issue.Name AS Expr2, contact.cust_name, contact.ph_no, contact.time, time_frame.Estmtd_Hrs, time_frame.Hrs_Spent, time_frame.internal_status FROM issue INNER JOIN project ON issue.pro_id = project.pro_id INNER JOIN contact ON issue.issue_id = contact.issue_id INNER JOIN time_frame ON issue.issue_id = time_frame.issue_id" 
            UpdateCommand="UpdateTwoTables" UpdateCommandType="StoredProcedure">

以下是我的更新参数

<UpdateParameters>
                <asp:Parameter Name="mem_id" Type="String" />
                <asp:Parameter Name="priority" Type="String" />
                <asp:Parameter Name="status" Type="String" />
                <asp:Parameter Name="hrs" Type="String" />
                <asp:Parameter Name="i_status" Type="String" />
                <asp:Parameter Name="issue_id" Type="Int32" />
            </UpdateParameters>

以下是我的存储过程:

PROCEDURE [dbo].[UpdateTwoTables]
       (
       @mem_id varchar(20),
       @priority varchar(30),
       @status varchar(20),
       @hrs varchar(20),
       @i_status varchar(30),
       @issue_id int
       )
AS
       BEGIN

       UPDATE [issue] SET  [mem_id] = @mem_id, [priority] = @priority, [status] = @status WHERE [issue_id] = @issue_id
       UPDATE time_frame SET Estmtd_Hrs=@hrs, internal_status=@i_status where issue_id=@issue_id

       END
       RETURN

我还尝试过以下SqlDataSource更新事件的解决方案,代码为:

 protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        DbParameterCollection CmdParams = e.Command.Parameters;
        ParameterCollection UpdParams = ((SqlDataSourceView)sender).UpdateParameters;

        Hashtable ht = new Hashtable();
        foreach (Parameter UpdParam in UpdParams)
            ht.Add(UpdParam.Name, true);

        for (int i = 0; i < CmdParams.Count; i++)
        {
            if (!ht.Contains(CmdParams[i].ParameterName.Substring(1)))
                CmdParams.Remove(CmdParams[i--]);
        }
    }

上面的代码删除了我的错误,但只更新了1个表第二个表没有更新。请有人帮帮我。感谢

0 个答案:

没有答案