简体   繁体   English

存储过程期望未提供的参数

[英]Stored procedure expects parameter that was not supplied

I have a SqlDataSource connected to a GridView and I am trying to get the edit working correctly, but with everything I try I still get that parameters are not supplied. 我有一个连接到GridView的SqlDataSource ,我试图使编辑正常工作,但是我尝试使用的所有方法仍然得到未提供参数的信息。

I have tried naming the parameters with and without the '@', it seems to make no difference. 我尝试使用和不使用'@'来命名参数,这似乎没有什么区别。 As you can see in the below image, the update parameters exist and even have values! 如下图所示,更新参数存在,甚至具有值!

Example image: 示例图片:

错误图片

ASPX markup: ASPX标记:

<asp:GridView runat="server" ID="JobGV" DataSourceID="JobApprovalsDS" 
     AutoGenerateColumns="False" AutoGenerateEditButton="true" 
     OnRowCommand="JobGV_OnRowCommand" OnRowUpdating="JobGV_OnRowUpdating">
    <Columns>
        <asp:BoundField HeaderText="Function" DataField="FunDesc" ReadOnly="true"/>
        <asp:BoundField HeaderText="Employee" DataField="EmpName" ReadOnly="true"/>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:DropDownList runat="server" ID="ddlEmps" SelectedValue='<%# Eval("appEmpID")%>' DataSourceID="EmpDS" DataTextField="EmpName" DataValueField="EmpID" />
                <asp:Label runat="server" ID="data" Text='<%# Eval("appBusinessUnit") +";" + Eval("appFunctID") %>' Visible="False"></asp:Label>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Eval("EmpName") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="JobApprovalsDS" runat="server" 
     ConnectionString="<%$ ConnectionStrings:JobClose %>" 
     SelectCommand="up_JobApprovalsSelect" 
     SelectCommandType="StoredProcedure" 
     UpdateCommand="up_JobApprovalsUpdate">
    <SelectParameters>
        <asp:Parameter Name="ShowAll" DefaultValue="1" />
        <asp:Parameter Name="AllPhases" DefaultValue="1" />
        <asp:ControlParameter Name="BusinessUnit" ControlID="ddlEditJob" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="@BusinessUnit" Type="String"/>
        <asp:Parameter Name="@FunctID" Type="Int32"/>
        <asp:Parameter Name="@EmpID" Type="Int32"/>
        <asp:Parameter Name="@UpdateDate" Type="DateTime"/>
    </UpdateParameters>
</asp:SqlDataSource>

C#: C#:

protected void JobGV_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
            if (e.CommandName.Equals("Update"))
            {
                int empid = 0;
                string[] data;
                int index = int.Parse(e.CommandArgument.ToString());
                GridViewRow row = JobGV.Rows[index];
                DropDownList ddlemp = (DropDownList) row.FindControl("ddlEmps");
                empid = int.Parse(ddlemp.SelectedValue);
                Label lbl = (Label) row.FindControl("data");
                data = lbl.Text.Split(';');

                JobApprovalsDS.UpdateParameters["@BusinessUnit"].DefaultValue = data[0];
                JobApprovalsDS.UpdateParameters["@FunctID"].DefaultValue = data[1];
                JobApprovalsDS.UpdateParameters["@EmpID"].DefaultValue = empid.ToString();
                //JobApprovalsDS.UpdateParameters.Add("BusinessUnit", data[0]);
                //JobApprovalsDS.UpdateParameters.Add("FunctID", data[1]);
                //JobApprovalsDS.UpdateParameters.Add("EmpID", empid.ToString());
            }
}

protected void JobGV_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
    JobApprovalsDS.Update();
}

Are you talking about the update process?? 您在谈论更新过程吗?

Well, in your SqlDataSource , you're not specifying that the UpdateCommand is talking to a stored procedure... you need to specify the UpdateCommandType , too! 好吧,在您的SqlDataSource ,您没有指定UpdateCommand正在与存储过程进行通讯……您还需要指定UpdateCommandType (not just the SelectCommandType ) (而不仅仅是SelectCommandType

<asp:SqlDataSource ID="JobApprovalsDS" runat="server" 
     ConnectionString="<%$ ConnectionStrings:JobClose %>" 
     SelectCommand="up_JobApprovalsSelect" 
     SelectCommandType="StoredProcedure" 
     UpdateCommand="up_JobApprovalsUpdate"
     UpdateCommandType="StoredProcedure" >   **** this is missing from your code!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 存储过程需要参数但实际提供了参数? - Stored procedure expects parameter but parameter is actually supplied? 存储过程或函数需要未提供的参数 - Stored procedure or function expects parameter which was not supplied C#存储过程或函数需要未提供的参数 - C# Stored procedure or function expects parameter which is not supplied 使用Entity Framework调用存储过程时出现问题:期望参数未提供 - Problems calling a stored procedure using Entity Framework: expects parameter not supplied 存储过程需要未提供的参数 id 值 - Stored procedure expects parameter id value which is not supplied 实体框架调用存储过程需要未提供的参数 - Entity Framework calling stored procedure expects parameter which was not supplied 过程需要一个未提供的参数 - Procedure expects a parameter which was not supplied 过程或函数期望未提供的参数-参数在存储过程中(我认为) - Procedure or function expects parameter which was not supplied - Parameter is in stored procedure(I think) c#存储过程启动:过程或函数需要参数,但未提供 - c# stored procedure launch: Procedure or function expects parameter, which was not supplied C#Odbc存储过程调用-过程或函数需要未提供的参数 - C# Odbc Stored procedure call - Procedure or function expects parameter which was not supplied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM